# Determining where a function is called from

**URL:** <https://www.ruby-forum.com/t/determining-where-a-function-is-called-from/185137>\
**Category:** Rails\
**Created:** [March 14, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/determining-where-a-function-is-called-from/185137 "2010-03-14T23:07:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Merrell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4491bb/32.png) [@Will\_Merrell](https://www.ruby-forum.com/u/Will_Merrell)\
**Post date:** [March 14, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/determining-where-a-function-is-called-from/185137/1 "2010-03-14T23:07:05Z")

</div>

I have a function that I use in my code in a number of places. It does  
some database lookup, processes it and returns some content to display.  
However, it needs to know where it was called from so that it can set up  
some return links. Currently I call it from a controller like this:

```
@content = Content.getContent( "Hello from ", controller_name(),

```

action\_name() )

I want to dry up the code and get rid of the controller and action calls  
and move it to the model where it belongs, but the controller\_name and  
action\_name functions are not available in the model.

My question, is there any way for the code in the model to discover  
where the function was called from so that that information can be made  
available to the function without having to explicitly pass it.

Hope someone can help,  
– Will
