Forum: Ruby on Rails Need help on rjs calls and partials

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
sa 1. (Guest)
on 2009-01-06 12:31
Hey all -

What I'm trying to accomplish is creating my own edit in place on a set
of data. Right now I'm just toying with some nonsense app, but when I
figure it out it'll be put to good use. I divide my code between the
view, the partial, the controller and the rjs template. For the sake of
example, I have a list of products and I'm trying to enable editing
their names:
----------
    # in the view
 <h1>Product List</h1>
 <table id="prod-table">
   <%= render :partial => 'product', :collection => @products, :locals
=> {:edit_mode => false }}%>
 </table>
 <%= link_to_function 'edit', go_to_edit_mode %>

 # in the partial
 <% @product = product %>
 <tr>
   <%  if edit_mode -%>
     <%= text_field :product, :name, :size => 10 %>
   <% else -%>
     <%= product.name  %>
   <% end -%>
 </tr>

 #in the controller (_product.html.erb)
 def go_to_edit_mode
   @prods = Product.find(:all)
   respond_to do |format|
     format.html { render :partial => 'product',
                          :collection => @prods,
                          :locals => {:edit_mode => false }}
     format.js
   end
 end

 # in the rjs (go_to_edit_mode.js.rjs)
 page.replace_html 'prod-table',
                   :partial => 'product',
                   :collection => Product.find(:all, :order => 'name'),
                   :edit_mode => true
----------
This is hardly working, though I think I'm going in the right
direction... Someone whos a seasoned rails developer will probably see
the problems right away, but since I'm new, I'd very much appreciate any
help I could get here - thanks.
This topic is locked and can not be replied to.