我想有向圖我的Ruby on Rails應用程序 我有兩個型號,標籤和連接Ruby on Rails的 - 造型有向圖
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錯誤:無法大規模指派保護的屬性: from_tag和to_tag「
,任何人都可以看到問題嗎?
這個問題顯然沒有任何from_tag和to_tag您attr_accessible列表。 – nurettin 2013-03-04 12:09:47
我跟着這個http://www.aquabu.com/2007/10/22/directed-graphs-in-ruby-on-rails/並按照他們的方式做了 – eoghanm 2013-03-04 12:12:20
他們沒有海量的任務安全回到2007年 – nurettin 2013-03-04 12:12:39