I have a model that contains data for many users/organizations. I need to limit the data by organization. I am trying to put this logic in the model vs the controller since many controllers/actions will be using that data. When I do that I get the following error:
undefined local variable or method `session' for Itstaff:Class
this is the code for the model:
class Itstaff < ActiveRecord::Base belongs_to :location has_many :servers has_many :consoles def self.user find(:all, :conditions => ["location_id in (?)",session[:location_ids]]) end end
The same code works fine from the controller.
session[:location_ids] gets initialized by the application controller during user log in. I tried to add an attr_reader in application controller but then my application hangs completely. I appreciate your help.