# Params checking in controller before real action

**URL:** <https://www.ruby-forum.com/t/params-checking-in-controller-before-real-action/130000>\
**Category:** Rails\
**Created:** [February 24, 2008, 2:22am UTC](https://www.ruby-forum.com/t/params-checking-in-controller-before-real-action/130000 "2008-02-24T02:22:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![beginner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e495f1/32.png) [@beginner](https://www.ruby-forum.com/u/beginner)\
**Post date:** [February 24, 2008, 2:22am UTC](https://www.ruby-forum.com/t/params-checking-in-controller-before-real-action/130000/1 "2008-02-24T02:22:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![beginner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e495f1/32.png) [@beginner](https://www.ruby-forum.com/u/beginner)\
**Post date:** [February 24, 2008, 3:39am UTC](https://www.ruby-forum.com/t/params-checking-in-controller-before-real-action/130000/2 "2008-02-24T03:39:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![beginner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e495f1/32.png) [@beginner](https://www.ruby-forum.com/u/beginner)\
**Post date:** [February 24, 2008, 6:49am UTC](https://www.ruby-forum.com/t/params-checking-in-controller-before-real-action/130000/3 "2008-02-24T06:49:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![beginner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e495f1/32.png) [@beginner](https://www.ruby-forum.com/u/beginner)\
**Post date:** [February 24, 2008, 9:07am UTC](https://www.ruby-forum.com/t/params-checking-in-controller-before-real-action/130000/4 "2008-02-24T09:07:51Z")

</div>

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 :).
