ruby-1.9.2-p0 > Subscription
=> Subscription(id: integer, email: string, tuan: boolean, send: boolean, create开发者_如何学Pythond_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?
精彩评论