On 28 Apr 2009, at 16:01, doug livesey wrote:
> Hi -- I've overwritten to_param on a couple of my models to have
> them use something more friendly to the eye in the browser address
> bar.
> I thought this would then appear in any routes I generated from
> *_path, but apparently not, as I have one route that I generate with
> this method call:
> job_process_step_path( @job, @process_step )
>
> ... that returns a url like this:
> /jobs/1/process_steps/2
>
> This is obviously using the ids of the models, and not my custom
> to_param method.
> Can anyone advise on how I can get this to behave as I want it to?
I do this on my sites. Here's an example from my jokes site:
--- My routes:
map.resources :categories do |category|
category.resources :jokes
end
--- I create the link thusly in my view:
<%= link_to "Permalink", category_joke_path(@joke.category,
@joke), :class => "comments" %>
--- I end up with the following path:
/categories/gross/jokes/Bear-guts
--- I define to_param in my models:
class Category < ActiveRecord::Base
…
def to_param
url_fragment
end
…
end
class Joke < ActiveRecord::Base
…
def to_param
urlid
end
…
end
And that's it! You can take a peek at the eventual outcome:
http://jokes-o-matic.com/categories/gross/jokes/Bear-guts
Don't know why it's not working for you though!
Will.
--
Will Jessop
Super Shiny Robot Limited - Professional web design and development
t: 07939 547 962
w: http://supershinyrobot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"NWRUG" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nwrug-members?hl=en
-~----------~----~----~----~------~----~------~--~---