kapso
kapso

Reputation: 11903

Rails 3 link_to question

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" 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

Upvotes: 2

Views: 282

Answers (2)

Dylan Markow
Dylan Markow

Reputation: 124419

get_user_path(user[:id]) should work since you're using a hash rather than an ActiveRecord model.

Upvotes: 1

sevenseacat
sevenseacat

Reputation: 25029

get_user_path(user) should work.

(Assuming user is an instance of your User model.)

Upvotes: 1

Related Questions