Hey all, I''m looking at this route below: map.resources :sessions, :member => {:validate => :get}, :new => {:start => :get}, :only => %w(create new) It''s clear the sessions has the 7 restful routes but each member of a collection of records can also be influenced by the validate method. Then I come across this line: :new => {:start => :get}, :only => %w(create new) and I''m not sure what this is doing. The sessions controller has these two methods: def new redirect_to start_new_session_path and return if current_user flash.now[:alert] = params[:error] if params[:error] flash.now[:notice] = params[:notice] if params[:notice] end def start end Thanks for response. -- 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.
I believe you only have two restful routes (create and new) because of the line: :only => %w(create new) And the start action is defined as an alternative new action here, probably because the original author wanted a GET instead of POST (/ sessions/start): :new => {:start => :get} Based on the SessionController it looks like you may have more routes then you are actually using. On Apr 26, 4:57 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey all, > > I''m looking at this route below: > > map.resources :sessions, :member => {:validate => :get}, :new => {:start > => :get}, :only => %w(create new) > > It''s clear the sessions has the 7 restful routes but each member of a > collection of records can also be influenced by the validate method. > Then I come across this line: > > :new => {:start => :get}, :only => %w(create new) > > and I''m not sure what this is doing. > > The sessions controller has these two methods: > > def new > redirect_to start_new_session_path and return if current_user > flash.now[:alert] = params[:error] if params[:error] > flash.now[:notice] = params[:notice] if params[:notice] > end > > def start > end > > Thanks for response. > > -- > 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.
M Daubs wrote in post #995201:> I believe you only have two restful routes (create and new) because of > the line: > > :only => %w(create new) > > And the start action is defined as an alternative new action here, > probably because the original author wanted a GET instead of POST (/ > sessions/start): > > :new => {:start => :get} > > Based on the SessionController it looks like you may have more routes > then you are actually using.Thanks for response. I''m not understanding why someone may need to pass an alternative new action, when both the new and start are declared as methods in sessions controller. If the reason is because these are two kinds of ''new'' actions that have different purposes, then why does start method silently return null since it doesn''t contain any functionality within its scope? Maybe the answer isn''t possible given the context I provided but in general terms, why might it be done? Thanks for response. -- 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.
Unless your routes file has a default :controller/:action route then the start action would be unroutable without that entry. It could even be redundant or unused. The start method may return nil but the sessions/start view will still render (if it exists). On Apr 26, 6:40 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> M Daubs wrote in post #995201: > > > I believe you only have two restful routes (create and new) because of > > the line: > > > :only => %w(create new) > > > And the start action is defined as an alternative new action here, > > probably because the original author wanted a GET instead of POST (/ > > sessions/start): > > > :new => {:start => :get} > > > Based on the SessionController it looks like you may have more routes > > then you are actually using. > > Thanks for response. I''m not understanding why someone may need to pass > an alternative new action, when both the new and start are declared as > methods in sessions controller. If the reason is because these are two > kinds of ''new'' actions that have different purposes, then why does start > method silently return null since it doesn''t contain any functionality > within its scope? Maybe the answer isn''t possible given the context I > provided but in general terms, why might it be done? > > Thanks for response. > > -- > 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.
Max Reznichenko
2011-Apr-27 09:38 UTC
Re: what does :new => {:start => :get} mean in routes?
Hi, John Obviously>> map.resources :sessions, :member => {:validate => :get}, :new => {:start => :get}, :only => %w(create new)creates new route for you like the one you have in new method>> redirect_to start_new_session_path and return if current_userIf you had>> map.resources :sessions, :member => {:validate => :get}, :new => {:finish => :get, :brand => :get}, :only => %w(create new)then the new routes would have been:>> redirect_to finish_new_session_path and return if current_userand>> redirect_to brand_new_session_path and return if current_userMakes sense? On Apr 26, 11:57 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey all, > > I''m looking at this route below: > > map.resources :sessions, :member => {:validate => :get}, :new => {:start > => :get}, :only => %w(create new) > > It''s clear the sessions has the 7 restful routes but each member of a > collection of records can also be influenced by the validate method. > Then I come across this line: > > :new => {:start => :get}, :only => %w(create new) > > and I''m not sure what this is doing. > > The sessions controller has these two methods: > > def new > redirect_to start_new_session_path and return if current_user > flash.now[:alert] = params[:error] if params[:error] > flash.now[:notice] = params[:notice] if params[:notice] > end > > def start > end > > Thanks for response. > > -- > Posted viahttp://www.ruby-forum.com/.-- Sincerely, Max Reznichenko -- 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.
> Obviously >>> map.resources :sessions, :member => {:validate => :get}, :new => {:start => > :get}, :only => %w(create new) > creates new route for you like the one you have in new method >>> redirect_to start_new_session_path and return if current_userThanks for response. I do notice this: form_tag sessions_path creates sessions/create and so when the form is posted, create method of sessions controller is executed. One thing though. How does it know to post to create if it just says sessions_path and not create_sessions_path? Since there is only a new and create action, it just assumes that since a form is being posted, you must want it to go to create? Thanks for response. -- 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.