2012-05-06 6 views
1

は、私は2人の機種のユーザー(宝石を考案)とコントローラショーアクション

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(私はすでにDeviseユーザー名があります)とcurrent_userのプロファイルページへのリンクが表示されます。

ありがとうございます!

+0

'params'を貼り付けることはできますか? 'profile_path(@profile)'から '@ profile'を削除してみてください。 –

+0

同じエラーが表示されます。申し訳ありませんが、' params'はどういう意味ですか? –

+0

'phams'ハッシュは' @ profile'のurlを送信するすべてのパラメータを持っています。あなたは '@profile.id'を送り、コントローラの名前が' Profile'か 'Profiles'かどうかを確認するべきです。 –

答えて

0

実際にレイアウトを使用するアクションに@profileを設定していないようですので、ルートは生成されず、ルータにはルートを生成するためのIDが必要です。

@profileをアプリケーションレイアウトでレンダリングするアクションの何かに設定する必要があります。これは、おそらくグローバルbefore_filterの仕事です。