[Rails] call method dynamically on active record association
Hey all,
I have this in view:
- if site_action_enabled?(:site_flag_enabled, Site)
And I have this in application controller:
def site_action_enabled?(operation, resource)
if resource.is_a?(Class) && resource == Site
return current_user.site.call operation
else
return false
end
end
helper_method :site_action_enabled?
It gives me error:
undefined method `call' for
site-1:ActiveRecord::Associations::BelongsToAssociation
If I use something like send:
return current_user.site.send operation
It does not call the site_flag_enabled instance method, which returns
true or false (site_flag_enabled is a field in database for sites
table of tinyint type)
thanks for response
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home