0

我正在尝试使用 devise 为 beta 版本创建一个注册页面。

我想做的是在满足某些条件时允许用户注册。我想做这样简单的事情:

#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 只有在正确填写表格时才有效......所以我的问题还没有答案

4

1 回答 1

1

一个简单的前置过滤器怎么样。这样您就不必弄乱设计代码

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

  def new
    super
  end

  private
    def check_conditions
      #your conditions
    end
end
于 2013-08-20T18:08:48.853 回答