Wednesday, May 19, 2010

Loading a partial with a Javascript Helper in Ruby on Rails

Sometimes, you have content that you want reloaded whenever someone goes to a page - even if they hit the 'Back' button. I had a drop down that I was using for navigation on Placeforce, and I wanted it to update even if they hit back. The drop down was your standard select tag, with a simple onchange event that would navigate the user to another page.

When you hit back, the select was still where it was left. This is good for forms, but not good in this case.

Here's a simple rails example to help you out:

<%= update_page_tag { |page|
page[:content_div].replace_html( ... )
} %>

The "..." (or whatever html your generating) is what you're using now. Just wrap that with the update_page_tag { |page| page[:content_div].replace_html(...) }

Simple, took just a few minutes. I wasn't familiar with 'update_page_tag', so thought I'd share.

1 comment:

  1. Anonymous1:05 AM

    Method deprecated