2014-03-02 35 views
0

我是一個Rails新手,並試圖創建一個簡單的Rails4應用程序。我有Devise GEM生成的用戶模型,考試模型和參與模型均由腳手架生成器生成。在Rails4中有很多通過關係的表單和路由

這是我的模型:

class Examination < ActiveRecord::Base 
    has_many :participations 
    has_many :users, :through => :participations 
end 

class Participation < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :examination 
end 

class User < ActiveRecord::Base 
    has_many :participations 
    has_many :examinations, :through => :participations 
end 

和數據庫結構:現在

create_table "participations", force: true do |t| 
    t.integer "user_id" 
    t.integer "examination_id" 
    t.string "exam_language_preference" 
    .... 
    end 

    create_table "users", force: true do |t| 
    t.string "email" 
    t.string "first_name" 
    .... 
    end 

    create_table "examinations", force: true do |t| 
    t.string "name" 
    t.string "shortname" 
    t.datetime "exam_date" 
    end 

,我想創建結構,使用戶能夠註冊到考試。在Examinations(app/views/examinations/index.html.erb)的索引頁面中,我想在每個考試的缺省顯示,編輯和銷燬按鈕旁邊添加一個「註冊」按鈕。當用戶點擊「註冊」按鈕時,我希望他們看到一個頁面,他們可以選擇他們的考試語言偏好並提交他們的註冊。

另外我想要一個用戶只能有一次註冊考試。我的意思是他們可以註冊許多考試,但每個考試只有一次。

我讀了整個Rails指南,但找不到正確的答案。

我該怎麼做這種應用程序?

回答

0

那麼,你不會在導軌指南中找到你的具體問題的答案。 :)

我建議你閱讀更多關於:使用範圍選項

  • 屬性的驗證唯一性
  • 嵌套資源
+0

由於H-人。很高興看到你向我展示我的問題的路徑。 – msdundar