我有 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 的个人资料页面。
谢谢!