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
Just put it the shared logic in application_controller.rb.
- dan
–
Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000
Sorry, I meant to say in application.rb and use a before filter to
call for each necessary method.
- dan
–
Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000
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
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:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000