need help with rails 4 nested routes

16 views
Skip to first unread message

tom

unread,
Dec 10, 2014, 3:14:21 PM12/10/14
to Ruby on Rails: Talk
hi

i want to accomplish this:
forms/:id 
forms/:id/list (action list)

forms/:id/card/:x (action showcard)



  resources :forms do
      get  'list', :action => 'list' #<< ok
      get 'card/:x' , :action=> 'showcard'  #, :as => 'card'      <<crash no method defined...

  end


and how would my link_to path look like? im going in circles. thx

Pedro Fernandes Steimbruch

unread,
Dec 10, 2014, 4:56:36 PM12/10/14
to rubyonra...@googlegroups.com
Hi,

Some questions came up to my mind when looking at your routes.
  • Do you really need a list action? Doesn't index action fill your needs?
  • Card seems to be another entitity. If It is true it would be better to use nested routes.
Using nested routes is easy:
resources :forms do
    resources :cards, only: [:show] # if you need just show action :)
end

Checkout the docs for nested resources and here you can look for how to use link_to and nested routes :)

I'm sorry if I went in the wrong direction.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMc1BLAJShiTn8Lziv6WsATm6R2jUZ8ivrhRnq3uS8VdKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages