我在何处定义由多个控制器使用的帮助器方法时遇到了一些麻烦。未定义的方法`options_for_select'
我提取这种方法变成自己的模块:
module ColumnMapHelper
def drop_down_upload_file_types
options = [["Use the RoyaltyZone Sales Upload Template", "RZ"], ["Use my own data file (Quickbooks, iTunes, etc)", "Create New"]]
...
select_tag "file_upload_type", options_for_select(options, default), :id=>"upload_file_type_selection"
end
end
我把它在控制器和暴露它作为一个辅助方法:
class SalesDataController < ApplicationController
before_filter :login_required, :except => [:download]
include ColumnMapHelper
helper_method :drop_down_upload_file_types
当它在我的控制器的助手定义( app/helpers/sales_data_helper.rb)这很好,但现在我得到这个错误,当我的帮助方法在视图中调用时:
undefined method `options_for_select' for #<SalesDataController:0x109bbbd18>
我需要包含哪些模块?分享这样的佣工的最佳方式是什么?
是否有理由将其包含在控制器中? – 2013-02-15 23:31:06
我曾经在某处读过ApplicationController中的共享助手方法。 – 2013-02-17 14:49:23