在这方面,我需要做些什么。 我有<代码>Tournament模型,与有关。 用户代码>,通过<代码>编码>。
添加的“密码>是签字状态。 导游有起步时间,用户只能在比赛开始前60分钟登记。 之后,注册用户可以进行核对。 因此,基本上我有两种选择:国家
简言之,模型看着这一点。
class Signup < ActiveRecord::Base
REGISTERED = 0
CHECKED = 1
belongs_to :tournament
belongs_to :user
end
class Tournament < ActiveRecord::Base
has_many :signups
has_many :users, :through => :signups
end
class User < ActiveRecord::Base
has_many :signups
has_many :tournaments, :through => :signups
end
我用一些法典来保持这一缺陷。 问题在于,因为我有许多条件要牢记。 这里是我的实际代码(,将Slim用作一个排时发动机)。
- if logged_in?
- if current_user.registered_for?(@tournament)
- if @tournament.starts_at < 60.minutes.from_now
p Signups are closed, only registered users can now check in
- if current_user.registered_for?(@tournament)
= button_to "Checkin!", { :controller => :signups, :action => :update, :id => @tournament.id }, :method => :put
- else
= button_to "Cancel your registration for the tournament", { :controller => :signups, :action => :destroy, :id => @tournament.id }, :method => :delete
- elsif current_user.checked_in?(@tournament)
p You have already checked in.
- elsif @tournament.starts_at > 60.minutes.from_now
= button_to "Sign up for the tournament", :controller => :signups, :action => :create, :method => :post, :id => @tournament.id
- else
p
| The tournament starts in less than 60 minutes, you can t sign in
- else
p
| You need to
|
= link_to "log in", login_path
| to play
问题在于,我不知道如何使这一点更加清洁。 我指的是,我能为纽芬兰语增加助手,但是,如果是的话,如果是,则会给我带来帮助,因为有许多不同的组合。 简称:
- user isn t logged in
- it s over 60 until the tournament starts and user hasn t yet registered for the tournament
- it s over 60 until the tournament starts and user is already registered
- it s under 60 minutes, but user isn t registered yet
- it s under 60 minutes and user is registered but hasn t checked in
- it s under 60 minutes and user already checked in
And this is just the tip of the iceberg, because admins should see more information than a regular user, but I don t want to complicate this question.
主要问题是,我如何处理类似案件? 这样做似乎非常可怕,但我看不出任何其他更简单的方式。