Can't figure out how duplicate routes are differentiated by rails ...
Read routing from inside out and API as well as a few tutorials but
still don't get it!!! For example...
routes.rb
resources :minisections do
resources :questions
end
rake routes:
minisection_question GET
/minisections/:minisection_id/questions/:id(.:format)
questions#show
PUT
/minisections/:minisection_id/questions/:id(.:format)
questions#update
In the view:
<%= link_to 'Delete', minisection_question_path(:minisection_id =>
@minisection.id,
:id => question.id),
:confirm => 'Are you sure?',
:method => :delete %>
SO the GET, PUT, and DELETE routes are the same. The view listed above
ends up requesting the first route ie "show" method even though I have
:method => :delete. ...so how to specify to to rails to delete a
question!
have a second look at Chapter 2 on Resources. E.g. the table in section
2.2
explains that for the same path (/photos/:id) there are 3 different
routes,
with
different HTTP verbs GET, PUT, DELETE.
The trick is that there is not only the path (/photos/:id) that
differentiates the
route, but also the http VERB that is used. That is typically for a
single
member
(1 photo, not the collection):
GET for a non-state changing action (e.g. view the photo)
PUT to update a certain resource (e.g. update the description)
DELETE to destroy the resource (delete it)
Thank you! Your referral to the API for the link_to led to this:
Note that if the user has JavaScript disabled, the request will fall
back to using GET. I was really on the wrong track! I recently upgraded
to Rails 3.2 and most of my Javascript stopped working. I was going to
try to figure out why after solving this current problem but I guess I
have to move on to the Javascript issues...