H傢伙,首先讓我告訴你我是瘋狂的新手,所以我的問題可能聽起來很愚蠢。我想自定義home_controller.rb中的「index」方法,我知道正確的方法是使用裝飾器。所以我創建了這個文件app/controller/home_controller_decorator.rb。我在那裏有申請Spree裝飾
#應用程序/控制器/ home_controller_decorator.rb
HomeController.class_eval do
def index
# Empty method
end
end
原來大禮包指數方法看起來像
def index
@searcher = Spree::Config.searcher_class.new(params)
@products = @searcher.retrieve_products
respond_with(@products)
end
我希望,當我重新啓動與_decorator服務器添加它將在主頁上顯示我沒有產品,否則會崩潰。當應用這個裝飾和啓動服務器我得到這個消息
[email protected]:~/Desktop/spp> rails server -p 3000
/home/agop/Desktop/spp/app/controllers/home_controller_decorator.rb:1:in `<top (required)>': uninitialized constant Spree::BaseController (NameError)
from /home/agop/Desktop/spp/lib/spree_site.rb:5:in `block in <class:Engine>'
from /home/agop/Desktop/spp/lib/spree_site.rb:4:in `glob'
from /home/agop/Desktop/spp/lib/spree_site.rb:4:in `<class:Engine>'
from /home/agop/Desktop/spp/lib/spree_site.rb:2:in `<module:SpreeSite>'
from /home/agop/Desktop/spp/lib/spree_site.rb:1:in `<top (required)>'
from /home/agop/Desktop/spp/config/application.rb:11:in `<class:Application>'
from /home/agop/Desktop/spp/config/application.rb:10:in `<module:Spp>'
from /home/agop/Desktop/spp/config/application.rb:9:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:28:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:28:in `block in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我可能不是在熱潮預計的方式寫的裝飾。在home_controller.rb索引方法上應用這個裝飾器的正確方法是什麼?