Hi guys, I really thought I had this sorted, but I cant figure this out! I''m building an app (ruby 1.9.3, rails 3.2.2). The app has teams, and in my teams_controller I want to have a method called apply_to_coach_team, with a form that allows you to apply to coach a new team. The problem is, every time I click the link to go to the form I get the message: Couldn''t find Team with id=apply_to_coach_team The app seems to be going to the teams#show method, and looking for a team with the id above. in routes.db I have: match "/teams/apply_to_coach_team" => "teams#apply_to_coach_team", :as => :apply_to_coach_team my teams_controller is just an empty method def apply_to_coach_team end and my view is just a stub for now <h1> apply to coach new team </h1> My link to this page looks like this : <%= link_to "apply to coach new team", apply_to_coach_team_path, class: "btn btn-mini btn-action" %> Can anyone tell me what simple mistake I''m making please!?? Thanks in advance -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Run "rake routes" from the command line to see what the system expects. Depending on the results from "rake routes", you probably need to change your link to call the path method differently. Maybe you need to call it passing in @team.id, or maybe the method should have a different name. On May 8, 6:10 am, Michael Baldock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi guys, I really thought I had this sorted, but I cant figure this out! > > I''m building an app (ruby 1.9.3, rails 3.2.2). > > The app has teams, and in my teams_controller I want to have a method > called apply_to_coach_team, with a form that allows you to apply to > coach a new team. > > The problem is, every time I click the link to go to the form I get the > message: > > Couldn''t find Team with id=apply_to_coach_team > > The app seems to be going to the teams#show method, and looking for a > team with the id above. > > in routes.db I have: > > match "/teams/apply_to_coach_team" => "teams#apply_to_coach_team", :as > => :apply_to_coach_team > > my teams_controller is just an empty method > > def apply_to_coach_team > > end > > and my view is just a stub for now > > <h1> apply to coach new team </h1> > > My link to this page looks like this : > > <%= link_to "apply to coach new team", apply_to_coach_team_path, class: > "btn btn-mini btn-action" %> > > Can anyone tell me what simple mistake I''m making please!?? > > Thanks in advance > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
I got it! For anyone else who''s a bit rails rusty, and has forgotten this the route to the new method has to go BEFORE the other routes created by resources :teams match "/teams/apply_to_coach_team" => "teams#apply_to_coach_team", :as => :apply_to_coach_team resources :teams This makes sense when I think about it! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You could also do: resources :teams do member do get :action_which_acts_on_member end collection do get :action_which_acts_on_collection end end I find this cleaner, and this also generates named path helpers without requiring you to provide :as option. On Tue, May 8, 2012 at 4:06 PM, Michael Baldock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> I got it! > > For anyone else who''s a bit rails rusty, and has forgotten this the > route to the new method has to go BEFORE the other routes created by > resources :teams > > match "/teams/apply_to_coach_team" => "teams#apply_to_coach_team", :as > => :apply_to_coach_team > > resources :teams > > This makes sense when I think about it! > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- - Aziz M. Bookwala Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> | Github <http://github.com/azizmb> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Cheers for the help guys, the routes for members / the collection is interesting I''ll need to read more about how these work, cheers -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.