I have in my routes.rb map.resources :accounts This is fine for the standard crud routes. But then I add a method in the accounts_controller def logout blah blah end I want to link to it so I do: <%=link_to ''Logout'' ,:controller=>''accounts'', :action=>''logout''%> which creates: <a href="/accounts/logout">Logout</a> But it just calls the ''show'' method of the accounts_controller and trys to find an account with an id of ''logout'' What am I missing here? How can I call the logout method. It doesn''t seem to be a problem if I dont specify a controller, but in this case the link is in the layout and needs to specify the controller. Cheers George --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 27, 2008, at 4:40 PM, giorgio wrote:> > I have in my routes.rb > > map.resources :accounts > > This is fine for the standard crud routes. > > But then I add a method in the accounts_controller > > def logout > blah blah > end > > I want to link to it so I do: > > <%=link_to ''Logout'' ,:controller=>''accounts'', :action=>''logout''%> > which creates: > <a href="/accounts/logout">Logout</a> > > But it just calls the ''show'' method of the accounts_controller and > trys to find an account with an id of ''logout'' > > What am I missing here?map.resources :accounts, :collection => {:get => :logout} That should give you a accounts_logout_path named route you can use.> How can I call the logout method. > It doesn''t seem to be a problem if I dont specify a controller, but in > this case the link is in the layout and needs to specify the > controller. > > Cheers > George > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That doesn''t work. I can do: map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' Not very elegant though But what is the point of having the default routes if you cant get to them? Is the idea to make a named route for everything? G --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 27, 2008, at 5:29 PM, giorgio wrote:> > That doesn''t work.I had it backwards. Try this. map.resources :accounts, :collection => {:logout => get}> I can do: > map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' > Not very elegant though > But what is the point of having the default routes if you cant get to > them? > > Is the idea to make a named route for everything? > > G > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
map.resources :accounts, :collection => {:logout => :get} works...(:get not get) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can make named routes for everything using the technique Phillip posted, you could rearrange your actions to be more restful (maybe a sessions controller, and map login to sessions#create, or move your default routes to a different position in the routes file (order is important here). On Nov 27, 7:29 pm, giorgio <george.pever...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> But what is the point of having the default routes if you cant get to > them? > > Is the idea to make a named route for everything? > > G--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---