0

helper:all次のものapplication.rbcurrent_userすべてのコントローラーとビューで利用できると思いましたか?

class ApplicationController < ActionController::Base

  helper :all
  protect_from_forgery
  before_filter { |c| Authorization.current_user = c.current_user }

  def current_user_session
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
  end

  def current_user
    return @current_user if defined?(@current_user)
    @current_user = current_user_session && current_user_session.record
  end

  ...

  private

  ...

  protected

  ...

end

私のビューは次のcurrent_userようにメソッドを呼び出します:

- if current_user
  = link_to "Logout", logout_path

私はこの応答を得ます:

undefined local variable or method `current_user' for #<#<Class:0x007f971d812a48>:0x007f972050c378>

私は何が欠けていますか?

どうもありがとう、

スティーブン。

PS私は、失敗しているビューに関連付けられたコントローラーでこれを実験しました:

before_filter :current_user
4

1 に答える 1

1

ドキュメントから:

引数がシンボル :all の場合、コントローラーは ActionController::Base.helpers_dir の下にあるすべてのヘルパーを含めます (デフォルトは RAILS_ROOT の下の app/helpers/*/.rb です)。

あなたが探しています:

helper_method :current_user, :current_user_session
于 2012-10-18T11:18:44.863 に答える