accessing session data in rails models -
i need check whether thing's id in session variable.
my instinct add method thing model checks see whether thing's id in array stored in session variable.
class thing < activerecord::base ... def pinned? session[:pinned].include? self.id end end
the functionality trying create user selects bunch of different things list, stored in per-user session , retrieved @ later date printing.
rails seems prevent session access in model without hackery, i'm keen avoid. maybe i'm approaching problem wrong way round, or pinned? function belongs somewhere else?
thanks.
maybe pass method argument instead of accessing directly?
def pinned?(things) things.include? self.id end thing.pinned?(session[:pinned])
Comments
Post a Comment