我在何處定義由多個控制器使用的幫助器方法時遇到了一些麻煩。未定義的方法`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