# Anything like with\_scope for ActionController?

**URL:** <https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522>\
**Category:** Rails\
**Created:** [July 23, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522 "2006-07-23T19:45:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [July 23, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522/1 "2006-07-23T19:45:14Z")

</div>

There are areas of my application that “want” to use a url structure  
like

domain/\<human\_readable\_param\>////

Please note that the human readable parameter I need to inject is NOT  
related to the being used by the action/controller pair. It’s  
identifying a container object whose contains are operated on by the  
actions.

I currently have this working with routes, however I need to tack on  
an extra parameter to all the url generating functions (url\_for,  
form\_start\_tag, named\_route\_url…) to get the mapping to pick up the  
custom URL parameter. Having to remember to  
append :short\_name=\>@my\_object.short\_name (with or without to\_param  
magic), is getting annoying and the repetition is getting ugly.

Is there anything like ActiveRecord’s with\_scope function to “bind”  
this extra parameter once and make ActionController smart about  
propagating the extra parameter everywhere?

Thank you.

Eric

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [July 23, 2006, 11:03pm UTC](https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522/2 "2006-07-23T23:03:55Z")

</div>

Just put it the shared logic in application\_controller.rb.

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [July 23, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522/3 "2006-07-23T23:16:50Z")

</div>

Sorry, I meant to say in application.rb and use a before filter to  
call for each necessary method.

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [July 23, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522/4 "2006-07-23T23:17:06Z")

</div>

On Jul 23, 2006, at 5:01 PM, Dan K. wrote:

> Just put it the shared logic in application\_controller.rb.

I can’t find a clean way to do that. URLs are generated by Rails in  
several different class hierachies and there doesn’t seem to be one  
or two key functions to override. As a result even if I add custom  
functions to application\_controller its easily possible to miss a  
function.

Eric

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [July 24, 2006, 12:10am UTC](https://www.ruby-forum.com/t/anything-like-with-scope-for-actioncontroller/99522/5 "2006-07-24T00:10:28Z")

</div>

Yeah, I wasn’t suggesting any fancy Ruby magic of opening up Rails  
classes and adding an optional parameter.

I was just saying that you could create a bunch of your own methods  
like my\_url\_for and my\_form\_tag that would call the real functions  
with your parameter added. You would put your methods in  
application.rb. It’s not as DRY as opening up one class and getting  
the functionality for all methods, but it’s still DRY.

If you use my naming scheme and “miss a function” you’ll get an  
immediate application error.

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000
