自Rails 3.2更新以来,我遇到了一个奇怪的问题。
我有两个模型:
class User < ActiveRecord::Base
has_many :educations
accepts_nested_attributes_for :educations, :reject_if => lambda {|c| c[:school_name].blank?}, :allow_destroy => true
...
end
class Education < ActiveRecord::Base
belongs_to :user
...
end
在数据库中:
create_table :educations do |t|
t.integer :user_id
t.integer :school_id
t.date :start
t.date :end
t.string :concentration
t.timestamps
end
在表格中,我有这个:
= date_select('user[educations_attributes]', "start", :index => "index", :discard_day => :true, :start_year => 1950, :include_blank => true, :class => 'mini')
当我发送带有PUT的表格时,参数是这样的:
Started PUT "/users/1" for 127.0.0.1 at 2012-01-26 10:03:35 +0100
Processing by UsersController#update as XML
Parameters: {"user"=>{"educations_attributes"=>{ "1327568594259"=>{"school_name"=>"Test", "concentration"=>"Test concentration", "start(3i)"=>"", "start(2i)"=>"10", "start(1i)"=>"2003", "end(3i)"=>"", "end(2i)"=>"12", "end(1i)"=>"2010", "_destroy"=>""}}}
数据库插入是这样的:
[1m[35mSQL (0.3ms)[0m INSERT INTO `educations` (`concentration`, `created_at`, `end`, `school_id`, `start`, `updated_at`, `user_id`) VALUES ('Test concentration', '2012-01-26 09:03:35', NULL, 14, NULL, '2012-01-26 09:03:35', 1)
任何人都知道这是为什么?参数中的索引似乎是正确的。
非常感谢你!