Hi
I think I’m still in the newbie class of Rails programmers and I may
be trying to run before I can walk so this question may have a very
simple answer.
I have a page with a small form on it, say Orders. That works fine.
Associated with this form is an additional data set that has a many to
one relationship with Orders, say Line Items. This too is fine.
What I want to do is display the orders form and below that allow
users to display, add, edit and delete line items. The line items are
to be hidden when the form is first displayed with a link that rolls
down the line items and another that rolls them back up again. When
they roll down there’s a link next to each allowing the user to delete
the line item.
Most of this I have working!
They can click a Show Line Items lino_to_remote that displays the line
items:
<%= link_to_remote ‘Show Line Items’,
:update => ‘line_items’,
:url => { :action => ‘list’, :controller => ‘line_items’, :id =>
@order.id },
:complete => visual_effect(:blind_down, ‘line_items’)
%>
My list method looks like:
def list
@lineitems = Lineitem.find(:all, :conditions => “order_id =
#{params[:id]}”)
render :partial => ‘list’
end
My partial looks like:
Click a line item to edit it.
<% for lineitem in @lineitems %> <% @lineitem = lineitem %><%= in_place_editor_field :lineitem, :name, {}, {} %> <%= link_to 'Delete', { :action => 'destroy', :id => @lineitem, :controller => 'lineitem' }, :confirm => "Are you sure you want to delete this challenge?", :method => :post %>
<% end %>I have a similar link_to_remote that hides them again with a blind_up.
I’d like to know if I can do the hide without a call back to the list
action, I guess I can use any dummy action that avoids a trip to the
database? Anyway that bit works, I can show and hide my line items
fine.
What I can’t get my head around is how to refresh my list of line
items when I add one or delete one? The actual addition and deletion
work in that the database is updated; but I then want to refresh my
list and I can’t figure out just how to do this.
Any pointers gratefully received.
Thanks
David