添加条件以设计注册过程

时间:2013-08-15 21:24:27

标签: ruby-on-rails devise

我正在尝试使用设计制作测试版的注册页面。

我想做的是允许用户在某些情况被填写时注册。我想做这样简单的事情:

#app/controllers/registrations_controller.rb

def new
if conditions
    create account for user
end
end

有什么想法吗?

编辑//部分答案(通过评论建议)

以下是我在评论中使用链接所做的代码。不确定这是不是最好的方式...

def new
token = params["token"]
find_email = Invitation.find_by_token(token)
if find_email
  find_email.approved = true
  if build_resource({})
    find_email.save
    respond_with self.resource
  end
end

编辑2 只有在正确填写表单时它才有效...所以没有回答我的问题

1 个答案:

答案 0 :(得分:0)

过滤前的简单操作怎么样?这样你就不必乱用设计代码

class RegistrationsController < Devise::RegistrationsController
  before_filter :check_conditions, only: :new

  def new
    super
  end

  private
    def check_conditions
      #your conditions
    end
end