J
John Griffiths
hi again, I managed to work out how to create a new item via ajax and
the form_remote_tag, however don't know how to delete an item from the
table.
here's the code so far, doesn't work, keeps on popping up saying null.id
found (e.g. it doesn't know which item to destroy).
show.rhtml
<ul id='item_list'>
<%= render artial=>'item_list' %>
</ul>
_item_list.rhtml
<% for item in @list.items %>
<li id="item_<%= item.id %>"><%= item.body %>
<%= link_to_remote "delete", :update => "item_list",
:url => { :action => "destroy", :id => item.id }
<%= link_to_remote 'delete', { :action => 'destroy_item', :id =>
item.id }, :confirm => 'Are you sure?', :method => ost %>
</li>
<% end %>
item.rb (model)
class Item < ActiveRecord::Base
#validates_presence_of :body
belongs_to :list
acts_as_list :scope => :list
end
list.rb (controller)
def destroy_item
Item.find(params[:id]).destroy
render artial=>'list'
end
any ideas?
think i'm nearly there, just don't know where i'm going wrong?
appreciate it
the form_remote_tag, however don't know how to delete an item from the
table.
here's the code so far, doesn't work, keeps on popping up saying null.id
found (e.g. it doesn't know which item to destroy).
show.rhtml
<ul id='item_list'>
<%= render artial=>'item_list' %>
</ul>
_item_list.rhtml
<% for item in @list.items %>
<li id="item_<%= item.id %>"><%= item.body %>
<%= link_to_remote "delete", :update => "item_list",
:url => { :action => "destroy", :id => item.id }
<%= link_to_remote 'delete', { :action => 'destroy_item', :id =>
item.id }, :confirm => 'Are you sure?', :method => ost %>
</li>
<% end %>
item.rb (model)
class Item < ActiveRecord::Base
#validates_presence_of :body
belongs_to :list
acts_as_list :scope => :list
end
list.rb (controller)
def destroy_item
Item.find(params[:id]).destroy
render artial=>'list'
end
any ideas?
think i'm nearly there, just don't know where i'm going wrong?
appreciate it