2012-01-25 6 views
0

私は他の人が書いたアプリケーションで作業していますが、いくつかの機能強化とUIの調整を追加しようとしています。ビューのモデル属性にアクセスする(具体的にはapplication.html.erb)

UIを少し変更するために私の見解で使用できるDevise 'current_user'ヘルパーの行に沿って何かをしたいです。しかし、すべての認証と認可は手書きです。そのような何かを実装するについて行くための最善の方法で

<% if current_user.interface_id == 1 %> 
    <%= link_to 'Something', something_path %> 
<% else %> 
    <%= link_to 'Something Else', something_else_path %> 
<% end %> 

思考:

理想的には、私は次の線に沿って何かを行うことができるようにしたいですか?

答えて

1

あなたはapp/controllers/application_controller.rbにこのような何かを追加することができ、あなたのコントローラとビューの両方に利用できるcurrent_userオブジェクトを取得するには:

helper_method :current_user 
def current_user 
    @current_user ||= ..... # Punch in the logic here that retrieves the current user from the session, etc. 
end 
+0

は、非常にありがとうございます。魅力のように動作します。 – YuKagi