# Params & Class Methods

**URL:** <https://www.ruby-forum.com/t/params-class-methods/89315>\
**Category:** Rails\
**Created:** [March 19, 2007, 2:45pm UTC](https://www.ruby-forum.com/t/params-class-methods/89315 "2007-03-19T14:45:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimas.silkaitis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a698b9/32.png) [@rimas.silkaitis](https://www.ruby-forum.com/u/rimas.silkaitis)\
**Post date:** [March 19, 2007, 2:45pm UTC](https://www.ruby-forum.com/t/params-class-methods/89315/1 "2007-03-19T14:45:51Z")

</div>

Hello all! This is my first time posting to the list, so be  
gentle. 😉

Here’s my setup… I’ve created a controller class method for  
performing some access control actions during a before\_filter  
callback. What I’d like to do is access the params from within the  
class method without having to explicitly pass them in the  
controller. I’d like to check the path in the url for some finer  
grained authentication.

I’ve tried to do a couple of different ways, but I think params are  
either out of scope or not created by the time the before filter  
runs.

Is what I’m proposing possible?

Example of what I’d like to do:

in controller…  
class ProjectController \< ApplicationController  
class\_method\_call ‘do something’

… rest of controller code …  
end

in lib…  
module AccCheck  
def self.included(in\_sub)  
in\_sub.extend(ClassMethods)  
end

module ClassMethods  
def class\_method\_call(in\_string)  
before\_filter do |c|  
if !params[:id].nil?  
… check access …  
end  
end  
end  
end

end

---

<div class="post-metadata">

**Author:** ![rimas.silkaitis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a698b9/32.png) [@rimas.silkaitis](https://www.ruby-forum.com/u/rimas.silkaitis)\
**Post date:** [March 19, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/params-class-methods/89315/2 "2007-03-19T15:50:00Z")

</div>

rimas.silkaitis wrote:

> Example of what I’d like to do:
> 
> in controller…  
> class ProjectController \< ApplicationController  
> class\_method\_call ‘do something’
> 
> … rest of controller code …  
> end
> 
> in lib…  
> module AccCheck  
> def self.included(in\_sub)  
> in\_sub.extend(ClassMethods)  
> end
> 
> module ClassMethods  
> def class\_method\_call(in\_string)  
> before\_filter do |c|  
> if !params[:id].nil?  
> … check access …  
> end  
> end  
> end  
> end
> 
> end

There is no way params could be accessible at the class level because if  
it did, there would be a huge clash if your app ever exceeded one  
session (which is fairly likely after you deploy)! Imagine the params  
hash continuously getting over written whenever a new request would come  
in. There would be chaos, mass looting, and a sharp rise in suicides.

Why can’t you have: class\_method\_call(in\_string, params) again ???

ilan

---

<div class="post-metadata">

**Author:** ![rimas.silkaitis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a698b9/32.png) [@rimas.silkaitis](https://www.ruby-forum.com/u/rimas.silkaitis)\
**Post date:** [March 19, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/params-class-methods/89315/3 "2007-03-19T15:58:39Z")

</div>

Yikes… it sounds like if I could do that it could be a clash of  
biblical proportion. I really have no reason for not being able to  
pass the params in the controller. I was curious to know if something  
like that was accessible with the class method I was creating.

Thanks for the info.

On Mar 19, 9:50 am, Ilan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
