My problem is that:
I have a web service controller, it has bunch of public methods, each of
them has first argument userid, so I implement before_invocation method:
def validUser(name, args)
begin
@user = User.find(args[0])
rescue ActiveRecord::RecordNotFound
raise "Wrong user id!"
end
... ...
end
It not only check the userid is valid, it also get the @user object that
other methods can directly use. I want to expand it. My methods also use
other id arguments, like categaryid, productid. They should also be
mapped to ActiveRecord object. But they not necessary used by every
method, not always the 2nd or 3rd argument. If in my before_invocation
method, I can get the argument name list of each method, then I can know
which is the id argument, then I can convert them to ActiveRecord
object. Then I do not need to write below code in each methods that has
categaryid argument:
begin
@categary = Categary.find(categaryid])
rescue ActiveRecord::RecordNotFound
raise "Wrong categary id!"
end
Any one can tell me how to do?
Jack