這可能被認爲是rails 3 associations error的重新發布。但它是我無法理解的東西。但是,好的......繼承了這筆交易..我在這裏問了一個與表格模式有關的問題。該職位是what is bad in this table schema structure查詢內容爲:紅寶石上軌道協會新手
`CREATE TABLE "pages" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"title" varchar(255),
"body" varchar(255),
"author" varchar(255),
"email" varchar(255),
"reference" varchar(255),
"created_at" datetime,
"updated_at" datetime);`
我認爲我應該爲作者單獨的表,而這正是我試圖和搞砸了。任何人都可以告訴我這些協會究竟應該如何處理我的場景?我真的需要很好地理解ROR關聯。
編輯-1
這裏是我的網頁遷移代碼:
class CreatePages < ActiveRecord::Migration
def self.up
create_table :pages do |t|
t.string :title, :unique => true, :limit => 50
t.string :body, :limit =>255
t.string :email, :unique => true, :limit => 50
t.string :reference, :limit => 40
t.timestamps
end
end
def self.down
drop_table :pages
end
end
,這裏是我的作家遷移:
class CreateAuthors < ActiveRecord::Migration
def change
create_table :authors do |t|
t.string :author, :unique => true, :null => false, :limit => 50
t.timestamps
end
end
end
你試過看導遊嗎? http://guides.rubyonrails.org/association_basics.html – MrDanA 2012-02-12 15:17:59
@MrDanA是的,我看着它。但問題是我有一個與模型相關的窗體..當我從頁表中分離作者表時,我得到了一些錯誤,但我仍然無法糾正。我真的無法通過你寄給我的鏈接想到一個想法。 – Maverick 2012-02-12 15:24:58
你得到什麼類型的錯誤?你發佈的問題只是「協會應該如何工作」,而不是「我的表單中出現錯誤」(這是一個不同的問題)。 – 2012-02-12 15:27:09