views:

219

answers:

1

I would like to rerender some partial views in Ruby on Rails at a specific JavaScript event. Do you guys know how I could do that?

More specifically, i have some custom in-place-editor fields (from my own helper based on scriptaculous), and I would like to update some partials whenever new values are submitted on the fields. I do have a hookup to a JavaScript callback which will be called when the submit a value in the in-place-editor... but I do not know how to force the partials to reload.

+1  A: 

If you already have a callback you can use the great (but sometimes forgotten) remote_function thing:

callback = function() {
  <%= remote_function :update => "div_with_your_partial_id", :url => { :action => "an_action_rendering_your_partial" } %>
}

This will generate the same javascript that is generated whenever your use javascript helpers like link_to_remote.

Not sure how this would look like in Rails 3, though.

neutrino
Perfect answer, this is what I was looking for. Thank you! (For some reason it doesn't let me to upvote you unless you edit the answer again)
balint.miklos
edited - the url part was incorrect
neutrino
ah yeah, I noticed, forgot to make a not here about it... (I used named routes)... thanks again!
balint.miklos
remote_function is deprecated in rails3...and I feel like is more complicated because of it
scottschulthess