I have 2 models Users(devise gem) and Profiles where
class User < ActiveRecord::Base
has_one :profile
class Profile < AciveRecord::Base
belongs_to :user
Everything in the views of each model works fine, but I want to have a link_to in the application layout.
<% if user_signed_in? %>
<li><%= link_to current_user.username , profile_path(@profile) %></li>
But it shows me this error:
ActionController::RoutingError (No route matches {:action=>"show", :controller=>"profiles"})
My profile controller
def show
@profile = Profile.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @profile }
end
end
My rake routes:
profiles GET /profiles(.:format) profiles#index
POST /profiles(.:format) profiles#create
new_profile GET /profiles/new(.:format) profiles#new
edit_profile GET /profiles/:id/edit(.:format) profiles#edit
profile GET /profiles/:id(.:format) profiles#show
PUT /profiles/:id(.:format) profiles#update
DELETE /profiles/:id(.:format) profiles#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
I want that the link displays the currentuser.username ( I have Devise Username already) and link to the profile page of the current_user.
Thanks!
params? try removing@profilefromprofile_path(@profile)- Bhushan Lodhaparamsdid you mean? - Juan Artauparamshash which has all the parameters you send though url in this case@profile. You should send@profile.idand also check whether controller is namedProfileorProfiles- Bhushan Lodha