So lets say I have the following route in my routes.rb file -
get 'site/user/:id' => 'users#show', :as => :get_user
How do I use link_to create a link to a particular user id by using named route :get_user
# so this will spit out "site/user", but i want /site/user/23 as output
link_to 'Some User', :get_user
NOTE -: I dont want to map user as a resource in my routes file. Also "user"开发者_JAVA百科 object is a hash not an instance of my User model.
For now this is what I have. Looking for a cleaner approach, is there any?
link_to 'Some User', {:controller => 'users', :action => 'show', :id => "#{user[:id]}"}
I am on Rails v3.0.3
get_user_path(user[:id])
should work since you're using a hash rather than an ActiveRecord model.
get_user_path(user)
should work.
(Assuming user
is an instance of your User model.)
精彩评论