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 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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)
ah yeah, I noticed, forgot to make a not here about it... (I used named routes)... thanks again!
remote_function is deprecated in rails3...and I feel like is more complicated because of it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.