对于房间预订,我想包括房间选项。
选项及其连接表reservation_options 似乎正确插入到我的参数中,但我无法正确分配连接表的option_quantity 值。它给了我错误消息```没有将符号隐式转换为整数``
由于选项是在表单中动态生成的,因为它们取决于所选的 room_type,因此我尝试在创建操作中构建它们。但是,我无法遍历参数并构建它们(请参阅为我的尝试创建操作)。
参数
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7QJHgdYW8ubKiNpLPET7tYzGNyqmp69dafo8NDaAUBf2PL3CI9XhKmd/am2Mo/A93EFZQByltwe2e4wepMXdqw==", "reservation"=>{"rooms"=>{"room_type"=>"185"}, "arrival"=>"2019-10-25", "departure"=>"2019-10-26", "room_id"=>"266", "reservation_contact_attributes"=>{"first_name"=>"John", "last_name"=>"Doe", "street"=>"street", "street_number"=>"", "zipcode"=>"4049", "city"=>"Gent", "country"=>"", "email"=>"john@hotmail.com", "phone"=>""}, "payment"=>"not paid"}, "reservation_options_attributes"=>[{"option_id"=>"109", "option_quantity"=>"1"}, {"option_id"=>"110", "option_quantity"=>"1"}], "commit"=>"Save & proceed to additional options", "hotel_id"=>"109"}
楷模
class Reservation < ApplicationRecord
has_many :reservation_options, dependent: :destroy
has_many :options, through: :reservation_options
accepts_nested_attributes_for :reservation_options
end
class ReservationOption < ApplicationRecord
belongs_to :option
belongs_to :reservation
accepts_nested_attributes_for :option
end
class Option < ApplicationRecord
belongs_to :room_type
has_many :reservation_options, dependent: :destroy
has_many :reservations, through: :reservation_options
validates :name, presence: true
end
保留选项的输出 1
=> <ActionController::Parameters {"option_id"=>"110", "option_quantity"=>"1"} permitted: false>
保留选项的输出 2
=> #<ActiveRecord::AssociationRelation [#<ReservationOption id: 62, option_id: 110, reservation_id: 142, option_quantity: nil, created_at: "2019-10-25 12:27:45", updated_at: "2019-10-25 12:27:45">]>
慕容3067478
相关分类