我是一些在rails上使用ruby的新功能,所以我試圖調試我得到的這個錯誤,但是,從我的理解中,我正在使用prod代碼。在導軌上調試ruby錯誤
錯誤:
NoMethodError in JoinController#index
undefined method `join_template' for nil:NilClass
/app/controllers/join_controller.rb:5:in `index'
好了,所以線5在指數是:
elsif current_brand.join_template == 'tms'
所以很明顯current_brand爲零。該控制器是一個子類的AppController的,所以檢查出我看到current_brand是一個方法:
def current_brand
return @current_brand if defined?(@current_brand)
url_array = request.env['HTTP_HOST'].split('.').reverse
url = url_array[1] << "." << url_array[0]
@current_brand = Brand.find(:first, :conditions => ["url LIKE ?", "%" << url << "%"])
end
似乎總是返回@current_brand,但他們會繼續爲零。問題是什麼?