1
我有2名型號的用戶(設計GEM)和配置文件,其中控制器顯示行動
class User < ActiveRecord::Base
has_one :profile
class Profile < AciveRecord::Base
belongs_to :user
一切都在每個模型的意見工作正常,但我想在應用程序佈局的link_to。
<% if user_signed_in? %>
<li><%= link_to current_user.username , profile_path(@profile) %></li>
但它表明我這個錯誤:
ActionController::RoutingError (No route matches {:action=>"show", :controller=>"profiles"})
我的個人資料控制器
def show
@profile = Profile.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @profile }
end
末
我耙路線:
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
我希望鏈接顯示currentuser.username(我已經設置了用戶名)並鏈接到current_user的配置文件頁面。
謝謝!
可以粘貼'params'嗎?嘗試從'profile_path(@profile)'中刪除'@ profile' –
獲取相同的錯誤,不好意思,但是你的意思是哪個'params'? –
'params'哈希,它具有您在這種情況下通過URL發送的所有參數'@ profile'。您應該發送'@ profile.id'並檢查控制器是否被命名爲'Profile'或'Profiles' –