Administrate: uninitialized constant when using custom field more than 1 time

Created on 13 Dec 2015  路  3Comments  路  Source: thoughtbot/administrate

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

Most helpful comment

@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.

All 3 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleeplessByte picture SleeplessByte  路  4Comments

ghost picture ghost  路  4Comments

drewtunney picture drewtunney  路  3Comments

Reedian picture Reedian  路  4Comments

preist picture preist  路  4Comments