up vote 0 down vote favorite

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.

flag

1 Answer

up vote 1 down vote accepted

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.

link|flag
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 Feb 21 at 1:03
edited - the url part was incorrect – neutrino Feb 21 at 13:51
ah yeah, I noticed, forgot to make a not here about it... (I used named routes)... thanks again! – balint.miklos Feb 21 at 15:58

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.