Philip Hallstrom
2008-Sep-26 00:15 UTC
Ticket for Review: Extend named routes to support an object''s to_params() method (yes, i know that makes no sense :)
Hi all -
Thanks for taking a look!
Ticket:
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1115-path-to-extend-named-routes-support-for-an-objects-to_params-method
Description:
---------------------------------------------------------------------------------------
The title not make sense so here''s a brief description.
I have a route as follows:
map.school ''/schools/:state/:city/:id/:name''
This is done for SEO purposes. Generating URLs is a pain however.
Currently I need to specify every argument either in hash form or
positional form.
This patch extends named routing so that if my School class
defined "to_params()" I can do this:
school_path(@school)
This assumes that I have the following method in my School model
(and that I have some associations to State and City):
def to_params
{:state => state.full_name, :city => city.name,
:id => id, :name => name.downcase}
end
If that method exists it will call it and continue processing the
named route
using the returned hash. If it does not it will continue on as normal.
NOTE: This only works for named routes and only if there is a single
argument
to the named route.
One reason this comes in really handy is when using the subdomain-fu
plugin I can now specify what subdomain a model should always be
linked to within the model and forget about it.
---------------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---