doc_ufo
doc_ufo

Reputation: 77

No routes match for custom route

I'm configuring a custom page for my user profile called profile.html.erb

I'm having a

No route matches {:action=>"profile", :controller=>"users"}

In routes, I have:

resources :users do
  member do
    get :profile
  end
end

My users_controller.rb

def profile
  @user = User.find(params[:id])
  render 'profile'
end

Error occurs at this line:

<li><%= link_to "Profile", profile_user_path %></li>

my rake routes

profile_user GET    /users/:id/profile(.:format)   users#profile

The profile.html.erb is working as I can access

http://localhost:3000/users/1/profile

Upvotes: 1

Views: 96

Answers (1)

pdu
pdu

Reputation: 10413

Since this is a member route, you need to provide the member.

<li><%= link_to "Profile", profile_user_path(@user) %></li>

Just doing

<li><%= link_to "Profile", profile_user_path %></li> without giving the user would be a route for a collection.

Upvotes: 4

Related Questions