1

Active Admin を使用している Rails アプリがあります。基本的な流れは、インシデント モデルが他のモデルと関連付けられていることです。他のモデルの接続は問題ないように見えますが、特に 1 つのモデル (Involves) では、新しいインシデントを作成するときに、初期化されていない定数 Incident::Involf というエラーが発生します。

インシデント モデルは次のようになります

class Incident < ActiveRecord::Base
 # Relationships
 belongs_to :admin_user
 has_many :images
 has_and_belongs_to_many :incident_types
 has_and_belongs_to_many :involves
 has_and_belongs_to_many :special_considerations

 belongs_to :county
 belongs_to :location


 # Nested Attributes
 accepts_nested_attributes_for :images
 accepts_nested_attributes_for :county
 accepts_nested_attributes_for :location
 accepts_nested_attributes_for :incident_types
 accepts_nested_attributes_for :involves
 accepts_nested_attributes_for :special_considerations   
end

Involve モデルは次のようになります。

class Involve < ActiveRecord::Base

  # Relationships
  has_and_belongs_to_many :incidents

  # Aliases
  alias_attribute :name, :involved

end

ネストされたインシデントのアクティブ管理モデルは次のようになります

f.inputs "Vehicles Involved" do
    f.input :involves, :as => :check_boxes
 end

f.inputs "Special Considerations" do
    f.input :special_considerations, :as => :check_boxes
end

f.input :involves, :as => :check_boxes をコメントアウトしている場合、特別な考慮事項が機能しますが、コメントアウトしていない場合、このエラーが発生します。

データベースと関連付けを調べたところ、コードは他のものと非常に似ているため、何が問題なのかわかりません。

4

1 に答える 1

0

この問題は解決されました。

Involve の複数形か、involve がキーワードであることに問題があるように見えました。

モデル名を Incident_Involvement に変更したところ、問題は解決しました。

于 2012-07-10T20:39:13.220 に答える