告诉我这个问题。创建模型和迁移:
class CreateSmsSends < ActiveRecord::Migration
def up
create_table :sms_sends do |t|
t.integer :issue_number
t.string :sms_number
t.text :sms_text
t.boolean :send
t.boolean :deliver
t.timestamps
end
end
def down
drop_table :sms_sends
end
end
型号:
class SmsSend < ActiveRecord::Base
attr_accessible :issue_number, :sms_number, :sms_text, :send, :deliver
end
我正在尝试在控制台中执行:
> s = SmsSend.new
=> #<SmsSend id: nil, issue_number: nil, sms_number: nil, sms_text: nil, send: nil, deliver: nil, created_at: nil, updated_at: nil>
> s.issue_number = 1
它给出了这个:
ArgumentError: wrong number of arguments (2 for 0)
from /home/redmine_dev/.rvm/gems/ruby-2.2.3@redmine320/gems/activerecord- 4.2.5/lib/active_record/attribute_methods.rb:48:in `__temp__3756e646'
from /home/redmine_dev/.rvm/gems/ruby-2.2.3@redmine320/gems/activerecord- 4.2.5/lib/active_record/attribute_methods.rb:379:in `clone_attribute_value'
如果我试试这个:
s = SmsSend.new(issue_number: 12345, sms_number: '9865654697', sms_text: 'text', send: 0, deliver: 0)
它给出了这个:
NoMethodError: undefined method `[]' for nil:NilClass
from /home/redmine_dev/.rvm/gems/ruby-2.2.3@redmine320/gems/activerecord-4.2.5/lib/active_record/attribute_methods/before_type_cast.rb:47:in `read_attribute_before_type_cast'
from /home/redmine_dev/.rvm/gems/ruby-2.2.3@redmine320/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:160:in `block in original_raw_attribute'
请告诉我如何修复它?
答案 0 :(得分:1)
您可以通过在模型上定义send
列来严重破坏事物。
send
方法用于向Ruby对象发送消息。它是Ruby的基本组成部分,也是ActiveRecord明显依赖的一部分。您的列名称正在破坏该方法并使其在模型实例上不可用。
将您的send
列重命名为不会与内置方法名称冲突的内容。