Ruby on rails 铁路的形式和路线在铁路中有许多贯穿关系
我是Rails新手,正在尝试创建一个简单的Rails4应用程序。我有用户模型,它是由Desive GEM生成的,考试模型和参与模型都是由scaffold generator生成的 这些是我的模型:Ruby on rails 铁路的形式和路线在铁路中有许多贯穿关系,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我是Rails新手,正在尝试创建一个简单的Rails4应用程序。我有用户模型,它是由Desive GEM生成的,考试模型和参与模型都是由scaffold generator生成的 这些是我的模型: class Examination < ActiveRecord::Base has_many :participations has_many :users, :through => :participations end class Participation < Ac
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
现在,我想创建一个结构,让用户能够注册考试。在考试索引页面(app/views/executions/index.html.erb)中,我想在每个考试的默认显示、编辑和销毁按钮旁边添加一个“注册”按钮。当用户点击“注册”按钮时,我希望他们看到一个页面,在那里他们可以选择自己的考试语言偏好并提交注册
此外,我想一个用户只能注册一次考试。我的意思是他们可以报名参加很多考试,但每次只能报名一次
我读了整个Rails指南,但找不到正确的答案
我怎样才能做这种应用呢?好吧,你不会在rails指南中找到你具体问题的答案。:) 我建议您阅读更多关于:
- 使用范围选项验证属性的唯一性
- 嵌套资源
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