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

DELETE
/minisections/:minisection_id/questions/:id(.:format)
questions#destroy

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!

Thanks,

Dave

--
Posted via http://www.ruby-forum.com/.

--
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@googlegroups.com.
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.

Search Discussions

  • Peter Vandenabeele at Feb 12, 2012 at 7:46 am

    On Sun, Feb 12, 2012 at 4:14 AM, Dave Castellano wrote:

    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

    DELETE
    /minisections/:minisection_id/questions/:id(.:format)
    questions#destroy

    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!
    There are 2 aspects:

    1) resourceful routing

    In e.g. the "Rails Routing from the Outside In" tutotial


    http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default

    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)

    2) the exact workings of the link_to method

    Checkout this

    http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

    in detail.

    HTH,

    Peter


    --
    *** Available for a new project ***

    Peter Vandenabeele
    http://twitter.com/peter_v
    http://rails.vandenabeele.com
    http://coderwall.com/peter_v

    --
    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@googlegroups.com.
    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.
  • Dave Castellano at Feb 12, 2012 at 2:51 pm

    Peter Vandenabeele wrote in post #1045942:
    On Sun, Feb 12, 2012 at 4:14 AM, Dave Castellano
    wrote:
    minisection_question GET

    question!
    There are 2 aspects:

    1) resourceful routing

    In e.g. the "Rails Routing from the Outside In" tutotial


    http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default

    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)

    2) the exact workings of the link_to method

    Checkout this

    http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
    in detail.

    HTH,

    Peter


    --
    *** Available for a new project ***

    Peter Vandenabeele
    http://twitter.com/peter_v
    http://rails.vandenabeele.com
    http://coderwall.com/peter_v
    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...

    Thank you for your help!!

    Dave

    --
    Posted via http://www.ruby-forum.com/.

    --
    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@googlegroups.com.
    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.
  • Radhames brito at Feb 12, 2012 at 3:21 pm


    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...
    This in case you want an alternative to the js based destroy link

    http://railscasts.com/episodes/77-destroy-without-javascript

    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 12, '12 at 3:14a
activeFeb 12, '12 at 3:21p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase