0

非常にイライラする問題があります。

Railsのビューからヘルパーメソッドを呼び出すことができません.これは私が持っているものです:

ApplicationController.rb

class ApplicationController < ActionController::Base

   protect_from_forgery

   def current_user
     @current_user ||= User.find(session[:user_id]) if session[:user_id]
   end

   helper_method :current_user
   helper_method :all

  end

/app/views/welcome/_navi_bar.haml:

%ul.nav.nav-pills.pull-right
   %li.pull-right
      - if current_user
         %a.btn-small{"data-toggle" => "modal", :href => log_out_path, :role => "button"}
           %i.icon-user.icon-white
           %strong
             Log Out
       - else
         %a.btn-small{"data-toggle" => "modal", :href => "#LoginBox", :role => "button"}
           %i.icon-user.icon-white
            %strong
             Login

これは私がエラーとして得るものです:

undefined local variable or method `current_user' for #<#<Class:0x007ff0a0544668>:0x007ff0a05414b8>

私は本当に問題が何であるかを理解していません。助けてください !

4

1 に答える 1

0

アプリケーション ヘルパーではなく、アプリケーション コントローラーでコードを記述しました。これが、メソッドが呼び出されない理由です。

現在のユーザーがログインしているかどうかを確認したい場合は、アプリケーションコントローラーの前にフィルターを使用してメソッドを呼び出すことができます

メソッドをチェックする必要がないときはいつでも、その場所でフィルターの前にスキップを追加します

于 2013-06-27T13:14:56.573 に答える