2
我試圖將應用程序移動到軌道3.1。我的許多測試中斷,因爲提交按鈕不再有一個ID。 Release Notes (see sect. "5.3 - Action View")確認它:獲取自動ID的提交標籤返回導軌3.1
提交表單助手不會再生成id「object_name_id」。
以下是更改action_view/helpers/form_helper.rb的relevant commit。
我想讓舊的行爲回來,而不是搞亂已安裝的寶石或手動更改所有視圖。所以我嘗試猴子修補它:
# this is config/initializers/FormHelperMonkeypatch.rb
module ActionView
module Helpers
module FormHelper # <-- this is the line phoet repaired, see his answer below
# code from rails 3.0
def submit(value=nil, options={})
value, options = nil, value if value.is_a?(Hash)
value ||= submit_default_value
@template.submit_tag(value, options.reverse_merge(:id => "#{object_name}_submit"))
end
end
end
end
我重新啓動我的服務器,但我看不到我的補丁的影響。我究竟做錯了什麼?
謝謝! s/module FormHelper/class FormBuilder /解決了我的問題! – bjelli 2012-01-14 23:10:15