Limit a user to view only associated records in rails
Posted
by trobrock
on Stack Overflow
See other posts from Stack Overflow
or by trobrock
Published on 2010-04-27T17:44:20Z
Indexed on
2010/04/27
17:53 UTC
Read the original article
Hit count: 377
I have an application with three Models (Profile -> SubModel -> SubSubModel) chained together with has many relationships. I am trying to limit a user, after logging in, to only retrieving records that are associated with their Profile. I am very new to rails and this is what I had been trying in the Profile model
has_many :submodels, :conditions => {:profile_id => self.id}
but this is returning an empty data set when calling with Profile.find_by_id(1).submodels, how else could I achieve what I am trying to do. Or should I handle this in the controller or view instead, I thought it sounded well suited for the model to handle this.
© Stack Overflow or respective owner