Passing an instance variable through RJS?

Posted by Elliot on Stack Overflow See other posts from Stack Overflow or by Elliot
Published on 2010-06-06T15:38:38Z Indexed on 2010/06/06 15:42 UTC
Read the original article Hit count: 330

Filed under:
|

Hey guys here is my code (roughly):

books.html.erb

<% @books.each do |book| %>
    <% @bookid = book.id %>
    <div id="enter_stuff">
    <%= render "input", :bookid => @bookid  %>
    </div>
<%end%>

_input.html.erb

<% @book = Book.find_by_id(@bookid) %>

<strong>your book is: <%=h @book.name %></strong>

create.rjs

page.replace_html :enter_stuff, :partial => 'input', :object => @bookid

The problem here is that only create.js doesn't seem to work (though, if instead of passing the partial I passed "..." it does work, so I know its that there are instance variables in the partial that aren't being reset. Any ideas?)

So the final question, is how do I pass an instance variable to a partial through the create.rjs file?

p.s. I know I will have duplicate div IDs, I'm not worrying about that for now though.

Best, Elliot

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about AJAX