Ruby on Rails アプリケーションの有向グラフをモデル化しようとしています。Tag と Connection の 2 つのモデルがあります。
class Connection < ActiveRecord::Base
attr_accessible :cost, :from_id, :to_id
belongs_to :from_tag, :foreign_key => "from_id", :class_name => "Tag"
belongs_to :to_tag, :foreign_key => "to_id", :class_name => "Tag"
end
class Tag < ActiveRecord::Base
attr_accessible :location_info, :reference
has_many :to_connections, :foreign_key => 'from_id', :class_name => 'Connection'
has_many :to_tags, :through => :to_connections
has_many :from_connections, :foreign_key => 'to_id', :class_name => 'Connection'
has_many :from_tags, :through => :from_connections
end
このようにタグを作成すると
a = Tag.create(:reference => "a", :location_info => "Tag A")
b = Tag.create(:reference => "b", :location_info => "Tag B")
それは正常に動作します。
でも二人を繋げようとすると
Connection.create(:from_tag => a, :to_tag => b, :cost => 5)
というエラーが表示されます
"ActiveModel::MassAssignmentSecurity::Error: 保護された属性を一括割り当てできません: from_tag および to_tag"
、誰でも問題を見ることができますか?