0

I am using devise for my auth and it works great. I need a profile page and I created a controller for Users and have a show method in there which links to show.html.erb and that works once the id is passed.

I want to add a link in the profile to go to the url /users/[:id] but I can't get it to work. I've tried:

match 'users/:id', :to 'users#show', :as => :profile

but I get error saying no action show.

Can anyone give me some advice to get a link to route to their profile.

Jonathan Allard
  • 18,429
  • 11
  • 54
  • 75
DMH
  • 2,529
  • 3
  • 24
  • 35

2 Answers2

6

If you want something to go /users/:id isn't it as simple as:

routes.rb

resources :users

view_file.html.erb

<%= link_to "Bob's profile", user_path(user_id) %>
AdamT
  • 6,405
  • 10
  • 49
  • 75
  • I tried that but get undefined local variable or method `user_id' for #<#:0x007fd19c13e870> I have resources :users – DMH Mar 08 '13 at 16:15
  • the user_id is the id you'd want to use. So, whose `id` do you want to see? If you want the current_user's profile you'd do it like <%= link_to current_user.name, user_path(current_user.id) %> Please keep in mind I'm making assumptions about the objects/attributes you have available. – AdamT Mar 08 '13 at 16:17
  • 2
    please note, if you use the example above it would be `profile_path(current_user.id)` – AdamT Mar 08 '13 at 16:19
0

Your route should be

match 'users/:id', :to => 'users#show', :as => :profile
                      ^^^^
alestanis
  • 21,519
  • 4
  • 48
  • 67