# Get argument name

**URL:** <https://www.ruby-forum.com/t/get-argument-name/112189>\
**Category:** Rails\
**Created:** [August 16, 2007, 6:04am UTC](https://www.ruby-forum.com/t/get-argument-name/112189 "2007-08-16T06:04:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack\_archer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jack\_archer](https://www.ruby-forum.com/u/jack_archer)\
**Post date:** [August 16, 2007, 6:04am UTC](https://www.ruby-forum.com/t/get-argument-name/112189/1 "2007-08-16T06:04:40Z")

</div>

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
