我在新VM上運行傳統Rails 2.3
(是的,我知道)應用程序。它正在運行Ruby v2.3.1
。我已經完成了所有建議的更改,以便讓此舊版應用在此版本上運行。除了這段代碼,一切都運行得很好,速度也更快。此代碼來自舊版本Advanced Recipes for Rails
,並且是error_handling_form_builder.rb
。如何更改此超級調用以明確傳遞參數?
首先,這裏的形式聲明:
<% form_for(:review, :builder => ErrorHandlingFormBuilder) do |f| %>
<%= f.collection_select :system_id, @systems, :id, :name, { :include_blank => "Select a Standard"}, { :onchange => remote_function(:url => { :action => :makes }, :submit => :text, :method => 'post') } %>
<div id="categoriesdiv">
</div>
<% end %>
此代碼工作正常,如果我刪除建設者PARAM。下面是來自ErrorHandlingFormBuilder
代碼:
helpers = field_helpers +
%w(date_select datetime_select calendar_date_select time_select collection_select) +
%w(collection_select select country_select time_zone_select) -
%w(label fields_for)
helpers.each do |name|
# We don't want to have a label for a hidden field
next if name=="hidden_field"
define_method name do |field, *args|
options = args.detect {|argument| argument.is_a?(Hash)} || {}
build_shell(field, options) do
super # This call fails
end
end
end
的調用super
上述失敗,以下錯誤:
implicit argument passing of super from method defined by define_method()
is not supported. Specify all arguments explicitly.
的代碼看,我不知道如何去改變它。
我知道我必須調用超有明確的論點,但我想這一點:
super(field, options)
,我也得到:
wrong number of arguments (given 2, expected 4..6)
我也試過:
build_shell(field, options) do
super(*args)
end
但我得到:
undefined method `map' for :id:Symbol
Did you mean? tap
它看起來好像在尋找collection
屬性*args
列表中的第二個屬性。但它是第一個。如果我通過field
作爲第一個參數,但是我得到Stack Level Too Deep
。
嘗試'超(* args)'而不是 –
它試過了。用結果更新問題。 – AKWF