嘗試通過表單創建/更新Form
模型時,我總是收到錯誤no implicit conversion of Symbol into Integer
。我已將其範圍縮小到form_params
中的actions_attributes
。 trigger_attributes
工作正常,如果actions_attributes
被刪除。我懷疑它與枚舉字段,雙重嵌套屬性和/或has_many
關係有關,但不確定。對於雙嵌套的has_many屬性,Rails 5「符號沒有隱式轉換爲整數」
關於什麼可能導致此錯誤的任何想法?
正在運行Rails 5.0.x和Ruby 2.3.x,下面是相關的模型和控制器。
class Form < ApplicationRecord
has_one :rule
accepts_nested_attributes_for :rule
end
class Rule < ApplicationRecord
has_one :trigger
has_many :actions
accepts_nested_attributes_for :trigger
accepts_nested_attributes_for :actions
end
class Trigger < ApplicationRecord
belongs_to :rule
enum name: [:example]
end
class Actions < ApplicationRecord
belongs_to :rule
enum name: [:example]
end
class FormsController < ApplicationController
...
private
def form_params
params.require(:form).permit(
:title,
:description,
rule_attributes: [
trigger_attributes: [:name],
actions_attributes: [:name]
]
)
end
end