我有一个check_in(保留)表单,在某些时候我想要一个嵌套表单来添加room_requests:
= nested_form_for @reservation, url: check_in_check_in_path, method: 'put' do |f|
= f.fields_for :guests do |guest_form|
= label_tag t('users.new.first_name'), nil, class: 'grey h2 input-label'
= guest_form.text_field(:first_name, class: 'check-in-input')
(...)
= f.link_to_add "Add guest", :guests
= f.fields_for :room_requests do |room_form|
= label_tag nil, t('rooms.new.category'), class: 'grey h2'
= room_form.select(:room_category_id, current_hotel.room_categories.collect {|p| [ p.category, p.id, rate: p.base_rate ] }, {}, class: 'dropdown form-input category-dropdown')
(...)
= f.link_to_add "Add room request", :room_requests
从上面的代码中,"添加访客"按钮工作,但"添加房间请求"没有。
来自预订模式:
class Reservation < ActiveRecord::Base
has_many :guests
accepts_nested_attributes_for :guests, allow_destroy: false
has_many :room_requests, dependent: :destroy, inverse_of: :reservation
accepts_nested_attributes_for :room_requests, allow_destroy: true
end
并且reservation_controller.rb:
class ReservationsController < ApplicationController
def reservation_params
params.require(:reservation).permit(
:start_date, :end_date, :status, :tag_list, :sales_channel_id,
:comments, :room_category_id, :client_id,
client_attributes: [:id, :hotel_id, :first_name, :last_name, :address, :country,
:doc_type, :doc_number, :email, :phone, :city],
room_requests_attributes: [:id, :adults, :children, :room_category_id, :hotel_id,
:price, :rate_id, :room_id, :_destroy],
guests_attributes: [:id, :first_name, :last_name, :nationality, :room_request_id,
:doc_type, :doc_number])
end
end
我错过了什么?
答案 0 :(得分:0)
乍一看,对于嘉宾来说,似乎有:
= f.link_to_add "Add guest", :guest
但是对于room_requests,你有:
= f.link_to_add "Add room request", :room_requests
尝试制作:room_requests singular =&gt; :room_request