On 19 Feb 2008, at 19:57, saljamil wrote:
>
> 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
>
You can''t (session is basically an instance method of your
controller). Models should be completely ignorant of the controller
layer. You should pass down the appropriate value as an argument to
the method defined in the model.
Fred> 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.
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---