Devise User Profile link_to

2019-09-01 11:49发布

问题:

So I am currently trying to figure out what path to use so when the user clicks on 'View Profile' the link will be domain.com/USERNAME instead of domain.com/profiles/show

My current code for the link is

<li><%= link_to "View Profile", profiles_show_path %></li>

my routes.rb is set at

get '/:id' to: 'profiles#show'

回答1:

You need to specify an user as parameter in your link:

<li><%= link_to "View Profile", profile_path(user) %></li>

In your routes:

get '/:id', to: 'profiles#show', as: :profile

So you're overriding the default profile_path().