ruby on rails 3 - default scope with condition -
i using rails 3.2.13 , ruby 1.9.3. having 3 models :- email user
i have 2 roles users => publisher or subscriber
i want know how can in rails if want have emails subscribers , publishers. such as, write email.find(####).publishers email.find(####).subscribers
without having different table subs , pubs. also, have has many through relationship between email , user.
also, want achieve default scope email.publishers.approved? should visible users others should hidden.
the way have field 'role' in emailuser model.
and in email model add following 2 methods:
def publishers self.users.where(:email_users=>{:role=>'publishers'}) end def subscribers self.users.where(:email_users=>{:role=>'subscribers'}) end
Comments
Post a Comment