# Using cookies in a model

**URL:** <https://www.ruby-forum.com/t/using-cookies-in-a-model/121746>\
**Category:** Rails\
**Created:** [November 30, 2007, 2:20pm UTC](https://www.ruby-forum.com/t/using-cookies-in-a-model/121746 "2007-11-30T14:20:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 30, 2007, 2:20pm UTC](https://www.ruby-forum.com/t/using-cookies-in-a-model/121746/1 "2007-11-30T14:20:09Z")

</div>

Well, let’s say I have an Article class. What I would like is being  
able to define a method like that :

def rated?  
if cookies[“rate-article-#{self.id.to\_s}”] == “rated”  
true  
else  
false  
end  
end

So that I can use it in my views to check if the current user has  
rated this article or not.

BUT the “cookies” method isn’t defined for ActiveRecord::Base  
I tryied to include many modules (ActionController::Cookies ,  
ActionController::Helper, …) and cannot succeed.

Any help is welcome.

Thanks,

Florent J.
