# Facebooker and Ruby on Rails on Facebook: Sessions problem

**URL:** <https://www.ruby-forum.com/t/facebooker-and-ruby-on-rails-on-facebook-sessions-problem/193084>\
**Category:** Rails\
**Created:** [August 10, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/facebooker-and-ruby-on-rails-on-facebook-sessions-problem/193084 "2010-08-10T22:41:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![noloman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a9a28c/32.png) [@noloman](https://www.ruby-forum.com/u/noloman)\
**Post date:** [August 10, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/facebooker-and-ruby-on-rails-on-facebook-sessions-problem/193084/1 "2010-08-10T22:41:05Z")

</div>

Hello everybody,

I am reading the book Facebook Platform Development in order to try to  
code a small game for Facebook, and I have come across a “little”  
problem: I am trying to insert a user every time this is logged, into a  
database in my computer. I am using a couple of methods written in the  
book, but there seems to be a couple of problems:

I can’t seem to retrieve the session\_key from Facebook using the  
Facebooker helpers for RoR, and thus this value is null into the table  
in my database.

Every time I reload the webpage, I can see that even though the  
facebook\_id is the same, the same user is added in another row to my  
table in the database, even though it shouldn’t; it’s just supposed to  
update the attribute session\_key if this changes -anyway, right now this  
is null.

These are the three methods I am using in order to perform all this:

def self.for(facebook\_id,facebook\_session=nil)  
user = User.find\_or\_create\_by\_facebook\_id(facebook\_id)  
unless facebook\_session.nil?  
user.store\_session(facebook\_session.session\_key)  
end  
end

def store\_session(session\_key)  
if self.session\_key != session\_key  
update\_attribute(:session\_key, session\_key)  
end  
end

# Re-create a Facebooker::Session object outside a request

def facebook\_session  
@facebook\_session ||= returning Facebooker::Session.create do  
|session|  
# Facebook sessions are good for only one hour storing  
session.secure\_with!(session\_key,facebook\_id,1.hour.from\_now)  
end  
end

Thanks a lot in advance to everybody!
