# Using Cookies in a Rails 3.0 Metal Class

**URL:** <https://www.ruby-forum.com/t/using-cookies-in-a-rails-3-0-metal-class/195562>\
**Category:** Rails\
**Created:** [September 25, 2010, 8:15am UTC](https://www.ruby-forum.com/t/using-cookies-in-a-rails-3-0-metal-class/195562 "2010-09-25T08:15:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bparanj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e9a140/32.png) [@bparanj](https://www.ruby-forum.com/u/bparanj)\
**Post date:** [September 25, 2010, 8:15am UTC](https://www.ruby-forum.com/t/using-cookies-in-a-rails-3-0-metal-class/195562/1 "2010-09-25T08:15:33Z")

</div>

I have the following class that works fine as a controller:

class Foo \< ApplicationController

def check  
unless cookies[:user\_id].nil?  
logger.info(“Cookies value is : #{cookies[:user\_id]}”)  
redirect\_to “[http://www.yahoo.com](http://www.yahoo.com)”  
else  
cookies[:user\_id] = { :value =\> “198”, :expires =\>  
180.days.from\_now }  
redirect\_to “[http://www.google.com](http://www.google.com)”  
end

end  
end

When I try to convert it to Metal : class Foo \< ActionController::Metal  
it complains about cookies method available I included the following  
line:  
include ActionController::Session::CookieStore

it still gives me the same error. When the metal class is in the  
controller  
directory it is at least finding the class. If I move it to lib  
directory I  
get : uninitialized constant Foo error. I included the line:

require File.expand\_path(‘…/…/…/config/environment’, **FILE** )  
unless  
defined?(Rails)

it still gives the same error.

My questions are:

1. What do I need to include my metal class in order to use the  
cookies  
method in Rails 3.0 ?
2. Where should I save my Rails metal app class file? in the  
controllers  
or lib directory?

TIA.
