user1946705
user1946705

Reputation: 2888

Rails 3 - link for delete item

I have list of images and for every image I have link for deleting. That link looks this:

<%= link_to 'delete image', {:controller => 'shops', :action => 'delimg', :imgid => u.id}, :confirm => 'Really?' %>

def logo puts params[:imgid] ... end

And I am getting an error Couldn't find Shop with ID=logo and app/controllers/shops_controller.rb:17:in `show' - I tried to add puts 'IN SHOW and it really looks, that after click on that link is called method show. I have no idea, how it is possible...

Could someone help me, please, where is the problem?

Upvotes: 1

Views: 1054

Answers (2)

DanneManne
DanneManne

Reputation: 21180

This is probably how I would have done it:

#routes.rb
resources :shops do
  delete :delimg, :on => :member
end

By adding that, there will be a defined route to the delimg action mapped to the delete method. And that makes it possible to do the following in the view:

<%= link_to 'delete image', delimg_shop_path(u.id), :method => :delete %>

delimg_shop_path is a path helper that exists because of what was added in the routes.rb

Upvotes: 1

TH Afridi
TH Afridi

Reputation: 432

you are displaying params[:ingid] in the logo method but in the link to action u have specified delimg?? modiefy your link to as

<%= link_to 'delete image', {:controller => 'shops', :action => 'logo', :imgid => u.id}, :confirm => 'Really?' %>

then it will work

Upvotes: 0

Related Questions