Hi, I''m learning about routing and trying to solve the problem below. Using update_scope_path in the view is routing to "users/show" rather than users/update_scope, with "update_scope" becoming the user id. ( The goal is to change session[:question_scope] to "vip" when the user clicks the button in the view. I assume I have to go to a controller action to do that.) In routes.rb: resources :users match ''/users/update_scope'', :to => ''users#update_scope'', :as => :update_scope In users_controller: def update_scope session[:question_scope] = "vip" end In users/show: <%= link_to ''Go'', update_scope_path, :class => ''btn btn-mini'' %> In debug params: --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess action: show controller: users id: update_scope -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
I would suggest doing this. resources :users scope ''/users'' do put ''update_scope'', to: ''users#update_scope'', as: :update_scope end That might work. What I''d honestly consider is making a scope controller and using the update action. If you don''t need the others, then your routes will look like this. resources :users do resources :scopes, only: [ :update ] end ~Johnneylee On Sat, Feb 2, 2013 at 9:35 AM, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hi, I''m learning about routing and trying to solve the problem below. > Using update_scope_path in the view is routing to "users/show" rather > than users/update_scope, with "update_scope" becoming the user id. > > ( The goal is to change session[:question_scope] to "vip" when the user > clicks the button in the view. I assume I have to go to a controller > action to do that.) > > In routes.rb: > resources :users > match ''/users/update_scope'', :to => ''users#update_scope'', :as => > :update_scope > > In users_controller: > def update_scope > session[:question_scope] = "vip" > end > > In users/show: > <%= link_to ''Go'', update_scope_path, :class => ''btn btn-mini'' %> > > In debug params: > --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess > action: show > controller: users > id: update_scope > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
So I can''t create an action in any controller that sets the session variable and then call it through the route? Can you tell me why it is going to users /show instead of users/update_scope? I am trying to understand how this works as well as get it working... Thanks! -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sat, Feb 2, 2013 at 6:35 AM, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Using update_scope_path in the view is routing to "users/show" rather > than users/update_scope, with "update_scope" becoming the user id. > > ( The goal is to change session[:question_scope] to "vip" when the user > clicks the button in the view. I assume I have to go to a controller > action to do that.)Yes.> In routes.rb:resources :users The above includes /users/:id, which *matches first* - winning! So the routing engine won''t ever get to your other route. match ''/users/update_scope'' Reverse the order in routes.rb and try it. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Thank you! -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.