Featured post
url - Normalizing params a named route in rails -
i'm again, wrestling rails 3 , routes.
here problem:
i created named route 1 example:
match '/download/artist/:artist/album/:albumname', :to => "albums#show", :as => :search, :via => :get
gives me route: search_path
i have classic 1 this: get "albums/show"
gives me route: albums_show_path
.
however, when i'm using search_path parameters this:
<%= link_to "#{result.name[0..50]}(...)", search_path(:artist =>result, :albumname => result.name), :class => "albumname" %>
, fails, not albums_show_path. here error:
no route matches {:controller=>"albums", :action=>"show", :artist=>"eddie vedder & ben harper", :albumname=>"my city of ruins / father's house (live) [benefiting artists peace , justice haiti relief] {digital 45}"}
i know because albumname parameter not escaped. after trying escape cgi.escape
, doesn't work. suppose have in route.rb, have no clue how.
do have idea on how it?
edit
the error says: no route match etc. when don't have parameter illegal characters, find route.
** edit rake routes
**
welcome_index /welcome/index(.:format) {:controller=>"welcome", :action=>"index"} albums_index /albums/index(.:format) {:controller=>"albums", :action=>"index"} albums_show /albums/show(.:format) {:controller=>"albums", :action=>"show"} search /download/artist/:artist/album/:albumname(.:format) {:controller=>"albums", :action=>"show"} albums_show_album_info /albums/show_album_info(.:format) {:controller=>"albums", :action=>"show_album_info"} albums_show_itunes /albums/show_itunes(.:format) {:controller=>"albums", :action=>"show_itunes"} albums_show_spotify /albums/show_spotify(.:format) {:controller=>"albums", :action=>"show_spotify"} albums_show_carrefour /albums/show_carrefour(.:format) {:controller=>"albums", :action=>"show_carrefour"} root /(.:format) {:controller=>"welcome", :action=>"index"}
you swap out illegal characters (whichever ones like) gsub:
<%= link_to "#{result.name[0..50]}(...)", search_path(:artist =>result, :albumname => result.name.gsub("/","\/").gsub("whateverelse", "newvalue"), :class => "albumname" %>
i think because / interpreted denoting path separation (i forget true name of it) in urls. can "daisy-chain" gsub if want; see above.
- Get link
- X
- Other Apps
Comments
Post a Comment