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”
# params[:type] works in here.
If not, what’s the best way to do this?
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.
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
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.
Both answers are truly great help to me.
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.
Trying to understand instance methods and scope of class :).