Topic: Parameters to RJS

Hello all,

I am working on my first "real" project in rails. I am rendering partials through link_to_remote using RJS to update a <div> without a reload. Allright, my question is this. Is there anyway to write a generic RJS file that accepts a div (for elementID) and a partial?

For instance I have the following:

page.replace_html 'display_left', :partial => 'philosophy'
page.visual_effect :highlight,  'display_left', :duration => 2, :startcolor => "\'#d7d6dc\'", :endcolor => "\'#f5f2f7\'"

Is it possible to rewrite that RJS so that it accepts 'display_left' and 'philosophy' as parameters instead?

Hope I wasn't too unclear in what I mean...


Re: Parameters to RJS

You could pass them through the URL then just call params[] in your RJS file:

page.replace_html params[:div_id], :partial => params[:partial_name]

Just keep in mind this may introduce a security risk as anyone can input any variable they want into here.

Does that answer your question?

Railscasts - Free Ruby on Rails Screencasts