2013-06-27 41 views
0

我有一個非常令人沮喪的問題。問題與視圖helper_methods rails

我不能叫從我rails.This意見任何輔助方法,是我:

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> 

我真的不明白問題所在。請幫忙 !

+0

雖然我不認爲它會導致問題,我建議刪除不必要的'是helper_method:所有'線。 – Domon

+0

@Domon沒有幫助:( –

回答

0

你已經寫在應用控制器,而不是應用助手 這就是爲什麼如果你想檢查當前用戶登錄你的方法是沒有得到所謂的

你可能只是使用的原因還是不 代碼在應用控制器過濾器之前並調用該方法

每當你不需要檢查方法

添加在那個地方濾波器之前跳過