Атрибуты даты из формы, которые не сохраняются в базе данных, а доступны как параметры - PullRequest
1 голос
/ 26 января 2012

У меня странная проблема с момента обновления 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)

У кого-нибудь есть идея, зачем это?Индекс в параметрах, кажется, правильный.

Заранее большое спасибо!

...