0
在我的數據庫中,我試圖獲得網點和文章之間的一對多關係。
我得到當使用這種關係以下錯誤:Rails Unidentified Method問題:undefined方法`outlet_id'
undefined method `outlet_id' for #<Article:0x007fc353887e58>
下面是型號:
class Article < ActiveRecord::Base
belongs_to :analyst
belongs_to :outlet
has_and_belongs_to_many :loe
attr_accessible :article_body, :author, :distribution, :loe, :most_important, :pubdate, :publication, :state, :submitted, :summary, :title, :url, :analyst_id, :loe_ids, :outlet_id
end
class Outlet < ActiveRecord::Base
has_many :articles, foreign_key: :title
attr_accessible :distribution, :name, :state, :article_ids
end
以下是架構:
create_table "articles_loes", :id => false, :force => true do |t|
t.integer "article_id"
t.integer "loe_id"
end
create_table "loes", :force => true do |t|
t.string "name"
t.string "customer"
t.integer "article_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "loes", ["article_id"], :name => "index_loes_on_article_id"
create_table "outlets", :force => true do |t|
t.string "name"
t.integer "articles_id"
t.integer "distribution"
t.string "state"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "outlets", ["articles_id"], :name => "index_outlets_on_articles_id"
這裏是請撥:outlet
:
<div class="span4">
<%= f.association :loe %>
<%= f.association :outlet %>
</div>
如果有人有任何想法,我會很感激他們。我想我可能需要一篇關於Outlets的文章索引?如果情況確實如此,我並不確定如何實施。提前致謝。
我想你已經錯誤地將「articles_id」添加到網點表中。您需要改爲在articles表中使用outlet_id。 –