josh
November 23, 2007, 2:31pm
1
Hi all
I’m having an authorization method that looks like the following:
def user_requests_authorization_to(right_name)
…
end
I find it boring to always use
user_requests_authorization_to(‘EDIT’)
user_requests_authorization_to(‘CREATE’)
etc., so I thought I could implement my own dynamic method, like the
dynamic finders! Instead of the calls above I’d like to call
user_requests_authorization_to_edit
user_requests_authorization_to_create
How can I achieve that? Thanks a lot, Josh
josh
November 23, 2007, 2:37pm
2
On 23 Nov 2007, at 13:31, Joshua M. wrote:
etc., so I thought I could implement my own dynamic method, like the
dynamic finders! Instead of the calls above I’d like to call
user_requests_authorization_to_edit
user_requests_authorization_to_create
You need to override method_missing, ie
def method_missing(method_id, *arguments)
if method_id looks like user_requests_authorization_to_something
user_requests_authorization_to(something)
else
super
end
end
Fred