You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What were you trying to do?
Setup admin dashboard for model with multi-word irregular inflection.
example:
I have a dashboard class: class MerchantBonusDashboard < Administrate::BaseDashboard
And inflector:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.irregular 'merchant_bonus', 'merchant_bonuses'
end
during render of the dashboard I get error:
Rails -- Exception: ActionView::Template::Error: uninitialized constant MerchantBonu
Did you mean? MerchantBonus
Rails ActiveSupport Inflector method classify expects a underscore (snake_case) table name, but here we are giving it a CamelCase model name. classify does incidentally work when the table_name arg is CamelCase and doesn't have an multi-word irregular inflection.
Seems like we should do an underscore operation on the CamelCase model name before classifying. e.g.
def model
to_s.chomp(DASHBOARD_SUFFIX).underscore.classify.constantize
end
I could also define an additional inflector for the CamelCase version inflect.irregular 'MerchantBonus', 'MerchantBonuses'. But that seems more of a hack that the proposed change above.
Happy to submit a PR if this seems like a reasonable fix or maybe I'm misunderstanding some aspect.
What versions are you running?
Rails - (6.1.7.4)
administrate - (0.19.0)
The text was updated successfully, but these errors were encountered:
Setup admin dashboard for model with multi-word irregular inflection.
example:
I have a dashboard class:
class MerchantBonusDashboard < Administrate::BaseDashboard
And inflector:
during render of the dashboard I get error:
Relevant part of the stack trace:
Looking at
lib/administrate/base_dashboard.rb:25:in 'model'
I see this impl:
to_s.chomp(DASHBOARD_SUFFIX)
=>'MerchantBonus'
.classify
=>'MerchantBonu'
Rails ActiveSupport Inflector method
classify
expects a underscore (snake_case) table name, but here we are giving it a CamelCase model name. classify does incidentally work when thetable_name
arg is CamelCase and doesn't have an multi-word irregular inflection.Seems like we should do an
underscore
operation on the CamelCase model name before classifying. e.g.I could also define an additional inflector for the CamelCase version
inflect.irregular 'MerchantBonus', 'MerchantBonuses'
. But that seems more of a hack that the proposed change above.Happy to submit a PR if this seems like a reasonable fix or maybe I'm misunderstanding some aspect.
The text was updated successfully, but these errors were encountered: