Easier way to generate paths
Posted
by Horace Loeb
on Stack Overflow
See other posts from Stack Overflow
or by Horace Loeb
Published on 2010-05-10T01:38:18Z
Indexed on
2010/05/10
1:48 UTC
Read the original article
Hit count: 408
ruby-on-rails
|routing
Songs on Rap Genius have paths like /lyrics/The-notorious-b-i-g-ft-mase-and-puff-daddy/Mo-money-mo-problems
which are defined in routes.rb
as:
map.song '/lyrics/:artist_slug/:title_slug', :controller => 'songs', :action => 'show'
When I want to generate such a path, I use song_url(:title_slug => song.title_slug, :artist_slug => song.artist_slug)
. However, I'd much prefer to be able to type song_url(some_song)
. Is there a way I can make this happen besides defining a helper like:
def x_song_path(song)
song_path(:title_slug => song.title_slug, :artist_slug => song.artist_slug)
end
© Stack Overflow or respective owner