I want to perform certain action in controller based on request parameters. Is there some way to access params in controller before a real action? Like in following code: class UsersController < ApplicationController # params[:type] in here does not work ssl_required :create if params[:type]=="something" def create # params[:type] works in here. end end If not, what''s the best way to do this? -- 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-/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 -~----------~----~----~----~------~----~------~--~---
It is not supposed to work this way, accessing instance methods in scope of class never worked. If you''ll describe in more details what are you trying to accomplish, you definitely will be taken care of. On 24 фев, 03:22, Jerry Liu <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I want to perform certain action in controller based on request > parameters. Is there some way to access params in controller before a > real action? Like in following code: > > class UsersController < ApplicationController > > # params[:type] in here does not work > ssl_required :create if params[:type]=="something" > > def create > # params[:type] works in here. > end > end > > If not, what''s the best way to do this? > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Gabe da Silveira
2008-Feb-24 05:49 UTC
Re: params checking in controller before real action
The controller classes are cached in production, so you can''t have declarations there that are conditional to a single request. Also, if you are using RESTful routing, what you are trying to accomplish won''t work very well anyway, because ssl_required performs a redirect, and if you are posting a new form, it will be lost in the redirect. My advice, just make the create method always SSL (and the :new method too so people don''t see a secure submission from an insecure page warning). If for some reason you really need one secure and one not, add a :secure_create method and split them up. On Feb 23, 2008, at 6:22 PM, Jerry Liu wrote:> > I want to perform certain action in controller based on request > parameters. Is there some way to access params in controller before a > real action? Like in following code: > > class UsersController < ApplicationController > > # params[:type] in here does not work > ssl_required :create if params[:type]=="something" > > def create > # params[:type] works in here. > end > end > > If not, what''s the best way to do this? > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Both answers are truly great help to me. The problem: I have an User update action which based on passed in parameter and do different things. I want to just secure "account" update that contains password. Not image update etc. What I am doing now: I have created two separate actions: update_account and edit_account, which will require secure access. Current edit and update action will handle other none secure updates. Still going: Trying to understand instance methods and scope of class :). -- 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-/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 -~----------~----~----~----~------~----~------~--~---