RubyMoney / money-rails

Integration of RubyMoney - Money with Rails
MIT License
1.8k stars 387 forks source link

Brand New Rails install throwing errors with attribute that contains an '_' #647

Closed cromulus closed 2 years ago

cromulus commented 2 years ago

Hi!

Install rails "6.1.4.1" to replicate:

rails new moneytest
cd moneytest
echo "gem 'money-rails'" >> Gemfile && bundle install
rails g money_rails:initializer
rails g scaffold order total:monetize underscored_attribute:monetize
rails db:create && rails db:migrate
# insert appropriate model lines, monetize :total etc.
rails runner "Order.create(total:100)" # works just fine
rails runner "Order.create(underscored_attribute:100)" # Borked

This is the error: /.rvm/gems/ruby-3.0.2/gems/activemodel-6.1.4.1/lib/active_model/attribute_assignment.rb:51:in_assign_attribute': unknown attribute 'spent_amount' for Order. (ActiveModel::UnknownAttributeError)`

And if you create a record, then try to update the monetized attribute: ~/.rvm/gems/ruby-3.0.2/gems/activemodel-6.1.4.1/lib/active_model/attribute_methods.rb:469:inmethod_missing': undefined method spent_amount=' for #<Order id: 2, underscored_attribute_cents: 0, underscored_attribute_currency: "USD", total_cents: 0, total_currency: "USD", created_at: "2021-11-22 00:29:56.840675000 +0000", updated_at: "2021-11-22 00:29:56.840675000 +0000", total: nil> (NoMethodError)