Reputation: 3149
I have strange problem. In my view I have code like this:
= link_to 'Destroy', quests_path(quest), method: :destroy, class: 'btn btn-danger'
But my url looks like this in this case:
http://localhost:8080/quests.1
and in the params I have
action: index
controller: web/quests
format: '1'
But I need id in the params instead of format. Please help me.
Edited: Exactly doesn't work method: :delete.
routes.rb file:
scope module: :web do
root to: 'quests#index'
match '/logout', to: 'sessions#destroy'
resources :quests, only: [:new, :create, :index, :destroy] do
get 'change_state', on: :member
end
resource :session, only: [:new, :create, :destroy]
resource :user, only: [:new, :create, :destroy] do
scope module: :user do
end
end
end
Upvotes: 3
Views: 1415
Reputation: 17949
You misspelled in
quests_path(quest)
correct is
quest_path(quest)
or just
quest
Wish it helps
Upvotes: 2
Reputation: 51181
This should work:
= link_to 'Destroy', quest, method: :delete, class: 'btn btn-danger'
The reason you get this error is you are passing url to quests#index instead of quests#show/destroy.
Upvotes: 1
Reputation: 639
The link should use the delete
method, like :
= link_to 'Destroy', quest, method: :delete, class: 'btn btn-danger'
See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Upvotes: 0