Hello, I am sure this is a simple problem but for some reason I can''t get it to work. I am trying to delete a record. My routes.rb has: map.resources :ads ...the AdsController has: def destroy @ad = Ad.find(params[:id]) @ad.destroy respond_to do |format| format.html { redirect_to(ads_url) } format.xml { head :ok } end end ...and the index.html.erb has: <ul> <% @ads.each do |ad| %> <li><%= link_to h(ad.name), ad %> [<%= link_to "Delete", ads_path (ad), :method => :destroy %>]</li> <% end %> </ul> But instead of destroying a record, it creates a new empty record. Also, when looking at the url of ''Delete'' I get http://localhost:3000/ads.%23%3Cad:0x24681b8%3E TIA, Elle --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
try changing the delete link to ad_path(ad) instead of ads_path(ad). On Mar 24, 10:30 pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I am sure this is a simple problem but for some reason I can''t get it > to work. > I am trying to delete a record. My routes.rb has: > map.resources :ads > > ...the AdsController has: > def destroy > @ad = Ad.find(params[:id]) > @ad.destroy > > respond_to do |format| > format.html { redirect_to(ads_url) } > format.xml { head :ok } > end > end > > ...and the index.html.erb has: > <ul> > <% @ads.each do |ad| %> > <li><%= link_to h(ad.name), ad %> [<%= link_to "Delete", ads_path > (ad), :method => :destroy %>]</li> > <% end %> > </ul> > > But instead of destroying a record, it creates a new empty record. > Also, when looking at the url of ''Delete'' I gethttp://localhost:3000/ads.%23%3Cad:0x24681b8%3E > > TIA, > Elle--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I get: ActionController::MethodNotAllowed Only get, put, and delete requests are allowed. which I don''t understand -- since isn''t the request delete?? On Mar 25, 4:10 pm, Andrew Bloom <akbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> try changing the delete link to ad_path(ad) instead of ads_path(ad). > > On Mar 24, 10:30 pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello, > > > I am sure this is a simple problem but for some reason I can''t get it > > to work. > > I am trying to delete a record. My routes.rb has: > > map.resources :ads > > > ...the AdsController has: > > def destroy > > @ad = Ad.find(params[:id]) > > @ad.destroy > > > respond_to do |format| > > format.html { redirect_to(ads_url) } > > format.xml { head :ok } > > end > > end > > > ...and the index.html.erb has: > > <ul> > > <% @ads.each do |ad| %> > > <li><%= link_to h(ad.name), ad %> [<%= link_to "Delete", ads_path > > (ad), :method => :destroy %>]</li> > > <% end %> > > </ul> > > > But instead of destroying a record, it creates a new empty record. > > Also, when looking at the url of ''Delete'' I gethttp://localhost:3000/ads.%23%3Cad:0x24681b8%3E > > > TIA, > > Elle--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Solved. 1. As Andrew suggested, I used ad_path(ad) in singular 2. I left the name of the method as destroy, so: def destroy ... end 3. Changed the :method => :delete so, my delete link ended up as: <%= link_to ''Delete'', ad_path(ad), :method => :delete %> Thanks, Elle On Mar 25, 4:28 pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I get: > > ActionController::MethodNotAllowed > Only get, put, and delete requests are allowed. > > which I don''t understand -- since isn''t the request delete?? > > On Mar 25, 4:10 pm, Andrew Bloom <akbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > try changing the delete link to ad_path(ad) instead of ads_path(ad). > > > On Mar 24, 10:30 pm, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello, > > > > I am sure this is a simple problem but for some reason I can''t get it > > > to work. > > > I am trying to delete a record. My routes.rb has: > > > map.resources :ads > > > > ...the AdsController has: > > > def destroy > > > @ad = Ad.find(params[:id]) > > > @ad.destroy > > > > respond_to do |format| > > > format.html { redirect_to(ads_url) } > > > format.xml { head :ok } > > > end > > > end > > > > ...and the index.html.erb has: > > > <ul> > > > <% @ads.each do |ad| %> > > > <li><%= link_to h(ad.name), ad %> [<%= link_to "Delete", ads_path > > > (ad), :method => :destroy %>]</li> > > > <% end %> > > > </ul> > > > > But instead of destroying a record, it creates a new empty record. > > > Also, when looking at the url of ''Delete'' I gethttp://localhost:3000/ads.%23%3Cad:0x24681b8%3E > > > > TIA, > > > Elle--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---