# Create my own dynamic "finder" method?

**URL:** <https://www.ruby-forum.com/t/create-my-own-dynamic-finder-method/121076>\
**Category:** Rails\
**Created:** [November 23, 2007, 2:31pm UTC](https://www.ruby-forum.com/t/create-my-own-dynamic-finder-method/121076 "2007-11-23T14:31:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 2:31pm UTC](https://www.ruby-forum.com/t/create-my-own-dynamic-finder-method/121076/1 "2007-11-23T14:31:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 2:37pm UTC](https://www.ruby-forum.com/t/create-my-own-dynamic-finder-method/121076/2 "2007-11-23T14:37:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/create-my-own-dynamic-finder-method/121076/3 "2007-11-23T14:48:01Z")

</div>

Thank you 🙂
