site has many contacts through a polymorphic relationship:
relationship between tables:
users: contact_id
contact: primary key, contactable_id, contactable_type
site: primary key
student: site_id
User model
belongs_to :contact
Contact model
has_one :user
belongs_to :contactable, :polymorphic => true, :dependent => :destroy
Site model
has_many :contacts, :as => :contactable
has_many :students
Students model
belongs_to :site
This successfully limits the students by site:
StudentsController
def index_scoper
if current_user.role_id == 8
super.site_staff_limit
else
super.with_state.with_site
end
end
Students model
named_scope :site_staff_limit, :conditions => {:site_id => 1}
The problem is different users will belong to different sites, so they can
only access student records of the site they belong to. I am having
difficulty making that named_scope above dynamic enough to accomplish this.
--
View this message in context:
http://old.nabble.com/dynamically-set-named_scope-based-on-current_user-tp27331346p27339013.html
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.