I'm running a legacy Rails 2.3
(yes, I know) application on a new VM. It's running Ruby v2.3.1
. I've made all of the recommended changes to get this old app running on this version. Everything runs great, and much faster, except for this code. This code is from the old Advanced Recipes for Rails
book and is error_handling_form_builder.rb
.
First, here's the form declaration:
<% 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 %>
This code works fine if I remove the builder param. Here's the code from 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
The call to super
above fails with following error:
implicit argument passing of super from method defined by define_method()
is not supported. Specify all arguments explicitly.
Looking at the code, I'm not sure how to change it.
I know I have to call super with the explicit arguments, but I tried this:
super(field, options)
and I get:
wrong number of arguments (given 2, expected 4..6)
I also tried:
build_shell(field, options) do
super(*args)
end
but I get:
undefined method `map' for :id:Symbol
Did you mean? tap
It seems like it's looking for the collection
attribute 2nd in the list of *args
. But it's first. If i pass field
as the first argument though, I get a Stack Level Too Deep
.