I ran into a strange error when using a same custom field more than 1 time in a dashboard.
This works fine:
# app/dashboards/some_dashboard.rb
ATTRIBUTE_TYPES = {
gender: Field::Select.with_options(options: ['male','female']),
}
# app/fields/select.rb
require "administrate/fields/base"
class Select < Administrate::Field::Base
end
# app/views/fields/select/_form.html.erb
<%= f.label field.attribute %>
<%= f.select field.attribute, options_for_select(field.send(:options)[:options], field.data), { include_blank: true } %> # UGLY HACK TO ACCESS PROTECTED field.options METHOD
This returns an uninitialized constant Administrate::Field::Select error:
# app/dashboards/some_dashboard.rb
ATTRIBUTE_TYPES = {
gender: Field::Select.with_options(options: ['male','female']),
role: Field::Select.with_options(options: ['manager','intern']),
}
# app/fields/select.rb
require "administrate/fields/base"
class Select < Administrate::Field::Base
end
# app/views/fields/select/_form.html.erb
<%= f.label field.attribute %>
<%= f.select field.attribute, options_for_select(field.send(:options)[:options], field.data), { include_blank: true } %> # UGLY HACK TO ACCESS PROTECTED field.options METHOD
@michaelimstepf - I think you should change Field::Select to Select in both places.
It looks like this is a duplicate of #280, but feel free to re-open if that doesn't solve your problem.
Also, btw - the changelog is a good place to check if you see unexpected behavior after updating.
Fixed, thanks, my bad. I'll definitely keep checking the changelog.
Most helpful comment
@michaelimstepf - I think you should change
Field::SelecttoSelectin both places.It looks like this is a duplicate of #280, but feel free to re-open if that doesn't solve your problem.