【发布时间】:2023-04-02 03:05:01
【问题描述】:
我的约会模型不断收到未经许可的参数。
这是我的模型
class Appointment < ApplicationRecord
belongs_to :client
belongs_to :trainer
end
class Trainer < ApplicationRecord
has_many :appointments
has_many :clients, through: :appointments
end
class Client < ApplicationRecord
has_many :appointments
has_many :trainers, through: :appointments
end
这是我的控制器,为了简洁起见,我只是列出了我的私有方法。
def appt_params
params.require(:appointment).permit(:appointment_date, client_id: [],
trainer_id: [])
end
错误显示培训师、客户的参数未经允许。 我在强参数方法中遗漏了什么吗?
这是我的约会/新视图
<%= form_for @appointment do |f| %>
<%= f.datetime_select :appointment_date %>
<%= f.collection_select :trainer, Trainer.all, :id, :first_name %>
<%= f.collection_select :client, Client.all, :id, :name %>
<%= f.submit %>
<% end %>
我将集合添加到我的 appt_params 方法中,但仍然遇到相同的错误。我仍然掌握 Rails 的窍门,任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: activerecord ruby-on-rails-5 strong-parameters