money-rails, Money#== supports only zero numerics - ruby-on-rails
I'm using the money-rails gem in my Rails application. It have worked perfectly until now, but I've recently started getting the following error:
Money#== supports only zero numerics
I'm not really sure what caused this or how to solve it. I have recently run bundle update so I guess that something have been updated. My gemfile looks like this:
gem 'money-rails', '~>1'
gem 'eu_central_bank', "~>1.3.0"
My implementation looks like this:
# model
monetize :price_in_cents
# fetch / converting currencies
eu_bank = EuCentralBank.new
Money.default_bank = eu_bank
eu_bank.update_rates
converted_price = eu_bank.exchange_with(Money.new(price_to_convert * 100, from_currency), to_currency)
This have as I mentioned worked before, so I'm not sure what is breaking it.
Any ideas?
Update
To test I tried with the following.
money = Money.new(100, from_currency)
Then I got the same error as before. But if I tried:
money = Money.new(0, from_currency)
It seems to work. I find that a bit strange.
Update
Here is the backtrace from when I try to save the record:
["/Users/[user]/.rvm/gems/ruby-2.5.1/gems/money-6.11.3/lib/money/money/arithmetic.rb:70:in =='", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations/numericality.rb:22:in!='", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations/numericality.rb:22:in validate_each'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validator.rb:150:inblock in validate'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validator.rb:147:in each'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validator.rb:147:invalidate'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:413:in block in make_lambda'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:197:inblock (2 levels) in halting'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:601:in block (2 levels) in default_terminator'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:600:incatch'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:600:in block in default_terminator'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:198:inblock in halting'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:507:in block in invoke_before'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:507:ineach'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:507:in invoke_before'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:130:inrun_callbacks'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:827:in _run_validate_callbacks'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations.rb:405:inrun_validations!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations/callbacks.rb:114:in block in run_validations!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:97:inrun_callbacks'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:827:in _run_validation_callbacks'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations/callbacks.rb:114:inrun_validations!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activemodel-5.1.6/lib/active_model/validations.rb:335:in valid?'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/validations.rb:65:invalid?'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/validations.rb:82:in perform_validations'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/validations.rb:50:insave!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/attribute_methods/dirty.rb:43:in save!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/transactions.rb:313:inblock in save!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/transactions.rb:384:in block in with_transaction_returning_status'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:235:inblock in transaction'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/transaction.rb:194:in block in within_new_transaction'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:inmon_synchronize'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/transaction.rb:191:in within_new_transaction'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:235:intransaction'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/transactions.rb:210:in transaction'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/transactions.rb:381:inwith_transaction_returning_status'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/transactions.rb:313:in save!'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activerecord-5.1.6/lib/active_record/suppressor.rb:46:insave!'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:245:in block in set_supported_currencys_for_product_variant'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:240:ineach'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:240:in set_supported_currencys_for_product_variant'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:224:inset_up_product_variant'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:208:in match_product_variant_to_product'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:84:inblock in get_products_from_api_data'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:75:in map'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:75:inget_products_from_api_data'", "/Users/[user]/Documents/Development/wondery/[appname]/lib/importers/bts_wholesaler_importer.rb:25:in import'", "(irb):2:inirb_binding'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/workspace.rb:85:in eval'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/workspace.rb:85:inevaluate'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/context.rb:380:in evaluate'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:491:inblock (2 levels) in eval_input'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:623:in signal_status'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:488:inblock in eval_input'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/ruby-lex.rb:246:in block (2 levels) in each_top_level_statement'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/ruby-lex.rb:232:inloop'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/ruby-lex.rb:232:in block in each_top_level_statement'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/ruby-lex.rb:231:incatch'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb/ruby-lex.rb:231:in each_top_level_statement'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:487:ineval_input'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:428:in block in run'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:427:incatch'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:427:in run'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/irb.rb:383:instart'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/railties-5.1.6/lib/rails/commands/console/console_command.rb:62:in start'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/railties-5.1.6/lib/rails/commands/console/console_command.rb:17:instart'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/railties-5.1.6/lib/rails/commands/console/console_command.rb:97:in perform'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/thor-0.20.0/lib/thor/command.rb:27:inrun'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in invoke_command'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/thor-0.20.0/lib/thor.rb:387:indispatch'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/railties-5.1.6/lib/rails/command/base.rb:63:in perform'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/railties-5.1.6/lib/rails/command.rb:44:ininvoke'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/railties-5.1.6/lib/rails/commands.rb:16:in <top (required)>'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:inrequire'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in block in require'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:inload_dependency'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in require'", "/Users/[user]/Documents/Development/wondery/[appname]/bin/rails:9:in'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in load'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:inblock in load'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in load_dependency'", "/Users/[user]/.rvm/gems/ruby-2.5.1/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:inload'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in require'", "/Users/[user]/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:inrequire'", "-e:1:in `'"]
The error comes from a numericality validation on your model.
Money gem does not allow to compare a money object with a Number, unless thee number is zero. Otherwise it expects you to compare Money with Money.
In irb you can try:
```ruby
2.5.1 :006 > Money.new(1000, "USD") != Money.new(1000, "USD")
=> false
2.5.1 :007 > Money.new(1000, "USD") != 1000
Traceback (most recent call last):
4: from /Users/andi/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
3: from (irb):7
2: from (irb):7:in `!='
1: from /Users/andi/.rvm/gems/ruby-2.5.1/gems/money-6.12.0/lib/money/money/arithmetic.rb:70:in `=='
ArgumentError (Money#== supports only zero numerics)
2.5.1 :008 > Money.new(1000, "USD") != 0
=> true
```
I believe that this error makes sense, as you can't really compare an arbitrary number with an amount of money in a given currency.
The money-rails gem again comes with it's own validators:
https://github.com/RubyMoney/money-rails#numericality-validation-options
Your backtrace shows that you are using the rails numericality validator instead.
You might also come across this error when you are writing specs:
expect(order.subtotal).to eq 123.45
# ArgumentError:
# Money#== supports only zero numerics
expect(order.subtotal).to eq Money.new(12345)
# works!
Money Rails automatically adds "_cents" to the attribute you are monetizing. Then it creates an instance of that model.price which includes
<Money fractional:1500 currency:DKK>
Hence, you cannot do model.price + 10 as it would cause the error you are getting.
You may therefore want to monetize price_to_convert, or any other value you are working with so that you can sum them up, etc.
Create a new migration file e.g.
rails g migration AddMoneytizeToOrders
change migration file so that it reads as follow (change column/attribute to your values)
class AddMonetizeToOrder < ActiveRecord::Migration[6.0]
def change
add_monetize :orders, :price_to_convert, currency: { present: false }
end
end
In your model you must include
monetize :price_to_convert_cents
then you can work with e.g.(rails c) Order.last.price_to_convert + Model.last.price, etc.
Please note that you cannot use self.[:price_to_convert] as money rails wouldn't understand it and you would get the error
money rails ActiveModel::MissingAttributeError (can't write unknown attribute...
Therefore use self.price_to_convert instead
Related
ruby / rails: TypeError: can't convert Symbol into Integer
I'm trying to update my Representation attributes ivpn & idirect (from a csv file via rake task but i just print here only the meat of the program) and getting the TypeError: # in Rails Console: representation = Representation.where(id: 977) # => Representation_id: 977, ivnp: false, idirect: false rows = Hash.[:ivpn => "", :idirect => "x"] # originally rows are coming from csv-file representation.update_attributes! ivpn: rows.any?{|r| r[:ivpn].present?}, idirect: rows.any? {|r| r[:idirect].present?} TypeError: can't convert Symbol into Integer from (irb):42:in `[]' from (irb):42:in `block in irb_binding' from (irb):42:in `each' from (irb):42:in `any?' What I'm missing here?
try this: representation.update_attributes! ivpn: rows.any?[{|r| r[:ivpn].present?}], idirect: rows.any? [{|r| r[:idirect].present?}]
Summing values from a hash
I have a model where I am am storing some related data in a hash like this: line_items_attributes"=>[{"major"=>"8762", "minor"=>"322", "description"=>"Engineering", "amount"=>"200000", "active"=>"1"}, {"major"=>"8762", "minor"=>"445", "description"=>"Tanks", "amount"=>"2100000", "active"=>"1"}, {"major"=>"8762", "minor"=>"500", "description"=>"Pipe, Valves & Fittings", "amount"=>"150000", "active"=>"1"}] I went this way to avoid another related model etc. I amy playing with this prototype from this website: http://daniel.fone.net.nz/blog/2013/10/19/prototyping-web-applications-in-rails-4/?utm_source=rubyweekly&utm_medium=email Anyway I want to all the 'amount' values. I have Googled a few solutions but I don't know enough about hashes to figure this out. I tried: 2.0.0-p247 :053 > line_items_attributes.inject(0) {|sum, hash| sum + hash["amount"]} TypeError: no implicit conversion of String into Integer from (irb):53:in `[]' from (irb):53:in `block in irb_binding' from (irb):53:in `each' from (irb):53:in `inject' from (irb):53 from /Users/dan/.rvm/gems/ruby-2.0.0-p247#global/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start' from /Users/dan/.rvm/gems/ruby-2.0.0-p247#global/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start' from /Users/dan/.rvm/gems/ruby-2.0.0-p247#global/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' I even tried adding hash["amount"].to_i but that didn't work. I think I am close but sure I am missing something obvious to someone more experienced. On a side note I have seen other hash notations show such as: line_items_attributes"=>[{major:"8762", minor:"322" etc. is there an advantage to this?
This works for me: 2.0.0p247 :028 > line_items_attributes = [{"major"=>"8762", "minor"=>"322", "description"=>"Engineering", "amount"=>"200000", "active"=>"1"}, {"major"=>"8762", "minor"=>"445", "description"=>"Tanks", "amount"=>"2100000", "active"=>"1"}, {"major"=>"8762", "minor"=>"500", "description"=>"Pipe, Valves & Fittings", "amount"=>"150000", "active"=>"1"}] => [{"major"=>"8762", "minor"=>"322", "description"=>"Engineering", "amount"=>"200000", "active"=>"1"}, {"major"=>"8762", "minor"=>"445", "description"=>"Tanks", "amount"=>"2100000", "active"=>"1"}, {"major"=>"8762", "minor"=>"500", "description"=>"Pipe, Valves & Fittings", "amount"=>"150000", "active"=>"1"}] 2.0.0p247 :036 > line_items_attributes.inject(0) {|sum, hash| sum += hash["amount"].to_i; sum} => 2450000
D'oh! After looking again I missed the fact that the data being stored was actually: {"line_items_attributes"=>[{"major"=>"8762", "minor"=>"322", "description"=>"Engineering", "amount"=>"200000", "active"=>"1"}, {"major"=>"8762", "minor"=>"445", "description"=>"Tanks", "amount"=>"2100000", "active"=>"1"}, {"major"=>"8762", "minor"=>"500", "description"=>"Pipe, Valves & Fittings", "amount"=>"150000", "active"=>"1"}]} So now I ran this: Model.find(1).data["line_items_attributes"].inject(0) {|sum, hash| sum + hash["amount"].to_i} and all is good. I probably don't need to store it that way but I was just using that prototype tutorial as an example. Thanks to those who took the time to look at this. I had figured it out on my own... sort of.
Auto-generated Dropdown with dependency in Surveyor (Rails gem)
I am trying to setup a question in surveyor (http://github.com/NUBIC/surveyor/) that has a dropdown box with values 1 to 50. The next question should only be visible if the the user chooses 1 in the first question. Here is my code to do this: survey "Test survey dependency", :default_mandatory => true do section "questions" do q_1 "Click on 1 to see the next question", :pick => :one, :display_type => :dropdown ((1..49).to_a + ["50 or more"]).each{|num| a num.to_s, reference_identifier: num.to_s} q "Hello?" a "Hello" dependency :rule => "A" condition_A :q_1, "==", {:answer_reference => "1"} end end Now, this should compare :q_1 with :a_0. However this is the error I get: rake surveyor FILE=surveys/survey.rb rake aborted! Bad references: q_1, a_0 /home/ari/.rvm/gems/ruby-1.9.3-p392/gems/surveyor-1.3.0/lib/surveyor/parser.rb:59:in `instance_eval' /home/ari/.rvm/gems/ruby-1.9.3-p392/gems/surveyor-1.3.0/lib/surveyor/parser.rb:120:in `report_lost_and_duplicate_references' /home/ari/.rvm/gems/ruby-1.9.3-p392/gems/surveyor-1.3.0/lib/surveyor/parser.rb:84:in `method_missing' (eval):1:in `parse' If I change condition_A to condition_A :q_1, "==", {:string_value => "1"}, it gets parsed successfully but the next question is still never shown. Everything in the example, kitchen_sink_survey.rb works fine. So it looks like setting :reference_identifier manually doesn't do anything. Is this a bug or by design? And can I do anything about it apart from test for the actual value?
This was actually a bug in surveyor, but it has now been fixed on github: https://github.com/NUBIC/surveyor/commit/a9b68f668da936fbe16fc89448e53c463b867dc0
Ruby Newbie strftime Time.Now
I have the following written in ruby t = Time.now t.strftime("%Y-%d-%m") SCHEDULER.every '1m', :first_in => 0 do |job| send_event('gmail_gh', {current: gmail.inbox.count(:after => Date.parse(t)), older: gmail.inbox.count}) But i get this error scheduler caught exception: can't convert Time into String /var/dashing/cdmdash/jobs/gmail_gh.rb:21:in `parse' /var/dashing/cdmdash/jobs/gmail_gh.rb:21:in `block in <top (required)>' /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rufus-scheduler-2.0.17/lib/rufus/sc/jobs.rb:231:in `call' /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rufus-scheduler-2.0.17/lib/rufus/sc/jobs.rb:231:in `trigger_block' /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rufus-scheduler-2.0.17/lib/rufus/sc/jobs.rb:191:in `block in trigger' /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rufus-scheduler-2.0.17/lib/rufus/sc/scheduler.rb:416:in `call' /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rufus-scheduler-2.0.17/lib/rufus/sc/scheduler.rb:416:in `block in trigger_job' I think it has something to do with the t variable and it not being a truing, I am new to Ruby so I am abit stuck
If you look at the gem documentation, you will see that the :after and :before params take in a date in the format of YYYY-MM-DD. From the gem Readme: gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20")) gmail.inbox.count(:on => Date.parse("2010-04-15")) Your code is passing in YYYY-DD-MM which is likely causing the error. Edit When you call strftime on a datetime object, it doesn't modify the object - only returns the string notation based on format you give. As a result, the Date.parse(t) is still getting Time.now was a parameter. Try this: t = Time.now.strftime("%Y-%m-%d") Date.parse(t)
Rails3 create method issue
ruby-1.9.2-p0 > Subscription => Subscription(id: integer, email: string, tuan: boolean, send: boolean, created_at: datetime, updated_at: datetime) ruby-1.9.2-p0 > Subscription.create("email"=>"dd") ArgumentError: wrong number of arguments (2 for 0) from /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/attribute_methods/read.rb:69:in `send' from /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/base.rb:1548:in `block in attributes=' from /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/base.rb:1544:in `each' from /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/base.rb:1544:in `attributes=' from /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/base.rb:1411:in `initialize' I used the above code. I want to use the create method to persist a record to db, but it throws an error. I am new to rails3. I have checked my syntax, didn't find any error. Am I missing something?
I have figured it out by myself. In subscription model, I used a send column. Send may be a keyword of rails so it threw an error. After I changed it to some other word e.g. 'subscribe', then it works fine. (I have encounted this issue when used a column named "type" too)
Did you override your initialize in your Subscription model?