2016-11-07 48 views
0

嘗試通過表單創建/更新Form模型時,我總是收到錯誤no implicit conversion of Symbol into Integer。我已將其範圍縮小到form_params中的actions_attributestrigger_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 

回答

0

我得到這個由def form_params下改變actions_attributes:actions:,以及作出相關改變的形式,改變fields_for :actions_attributesfields_for :actions工作。

我經常困惑什麼時候使用_attributes以及什麼時候不使用。如果任何人有關於何時使用的信息,我將不勝感激,如果你能提供一個鏈接到評論中的信息。謝謝。

相關問題