【发布时间】:2019-01-03 17:02:58
【问题描述】:
我有三种型号,汽车、服务和预约。
class Car < ApplicationRecord
belongs_to :user
has_many :appointments, dependent: :destroy
end
class Service < ApplicationRecord
has_many :appointments
end
class Appointment < ApplicationRecord
belongs_to :car
belongs_to :service
accepts_nested_attributes_for :service
end
我使用简单的表单来创建引用服务的汽车预约
<%= simple_form_for [@car, @appointment] do |a| %>
<%= a.input :date %>
<%= a.input :description, label: "descripción" %>
<%= a.input :location, label: "ubicación" %>
<%= a.association :service, as: :check_boxes, include_blank: false %>
<%= a.button :submit %>
<% end %>`
我的约会使用正确的服务保存,但服务的属性没有
@car = Car.find(params[:car_id])
@appointment = Appointment.new(appointment_params)
@service = Service.new(params[ :service])
@appointment.service = @service
@appointment.car = @car
def appointment_params
params.require(:appointment).permit(:date, :description, :location, :status, :requests, service_attributes:[:request, :price, :provider])
end
我认为问题出在参数上,但我不确定,我不知道我是否正确保存它们,service_attributes:[:request, :price, :provider]。
提前致谢! (我使用 Rails 5)
【问题讨论】:
标签: ruby-on-rails database parameters associations simple-form