ruby on rails - Trying to define named_scopes and other ActiveRecord relationships on all models -


I am trying to define the designated_scope for all my models in Rail applications.

Currently, I have got close access to this by typing initialization for ActiveRecord :: Base and putting regular methods in it. Of course, this does not provide any real benefit when it comes to making a query chain and may be the way to get the least rail-e work.

However, when I start trying, use Has_many, name_scope, etc. ... ActiveRecord methods.

When I think I name_scope may not be right, so I really want to help the name_scope defined in addition, is not interested in the current Ruby ACL GMS in.

initializers / in:

  class ActiveRecord :: base has_many (: permissions) name_scope (: acl_check, lambda | user_id, method | {: include = & gt; ;: Permission ,: Terms => [["Permissions. User_id =?", User_ID], ["Permissions. Method =?", Method], ["Permissions Classname =?", Self.class.name]] } End) # The permission check runs for the current example. Def check_acl? (User_id, Method) # Check the permissions by the user. Permission_check = Permission.find_by_user_id_and_instance_id_and_classname_and_method (user_id, self.id, self.class.name, method) if (Anumti_chek) # If the line exists, we examine allowed to generate a hit return (true) end # contribute # otherwise, permission check a missed a return (false) end end  

Ha_man < The possibility of / code> does not work because it is evaluated in the body of the class and is required for the expected foreign key class In which this inheritance was evaluated rather than classes. (With ID = 42 for example stored with blog_id = 42 blog model Many comments can be models, which are required to make it, they are based on the class name)

designated area Should work if it's right.

The legacy method should work.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -