Find existing session
Some notes:


@session: A method called find_or_create_session should not change the state of instance variables.
@sessions.find_by facebook_id: fbid is written twice. Use variables to avoid repetition. Also, the consensus in the Ruby community is to always write parens (except for DSL-like code).
Time.now - @session.last_exchange: You can perform that check in the  SQL query.
Your method is basically doing find_or_create_session = existing_session || new_session, let the code mimic it.


I'd write:

def find_or_create_session(fbid, max_age: 5.minutes)
  Session.find_by(["facebook_id = ? AND last_exchange &gt;= ?", fbid, max_age.ago]) ||
    Session.create(facebook_id: fbid, context: {})
end