2013-03-04 42 views
0

我想有向图我的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“

,任何人都可以看到问题吗?

+0

这个问题显然没有任何from_tag和to_tag您attr_accessible列表。 – nurettin 2013-03-04 12:09:47

+0

我跟着这个http://www.aquabu.com/2007/10/22/directed-graphs-in-ruby-on-rails/并按照他们的方式做了 – eoghanm 2013-03-04 12:12:20

+0

他们没有海量的任务安全回到2007年 – nurettin 2013-03-04 12:12:39

回答