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.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to