1

Right now in my Rails 3 app I'm rendering partials using rjs in my controllers. For example, when saving a new item to a table, I refresh the table:

respond_to do |format|
    format.js
    {
      render :update do |page|
         page["#table_div"].html(render :partial=> 'table');
      end
    }
end

I'm really stuck on how I would go about keeping the same functionality, but moving away from the use of rjs. How can I accomplish this using jQuery, JSON and unobtrusive javascript? Thanks in advance!

1 Answer 1

3

You can remove the respond_to block and have another view with the js.erb extension, named after your action of course.

Taking the 'show' method as an example:

In show.js.erb

$("#table_div").html("<%= escape_javascript(render('table'))%>");  

Here's a couple of resources that will help you get acquainted with Unobtrusive JavaScript in Rails 3.

  1. http://asciicasts.com/episodes/205-unobtrusive-javascript

  2. http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/

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

Comments

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.