titibouboul
titibouboul

Reputation: 1358

Add condition to devise sign up process

I'm trying to make a sign up page for a beta version using devise.

What I would like to do is to allow user to sign up if some conditions are filled. I would like to do simple thing like this :

#app/controllers/registrations_controller.rb

def new
if conditions
    create account for user
end
end

Any idea ?

Edit // Partial answer (suggested by comments)

Here is the code I did using link in comments. Not sure if it's the best way to do it though...

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

end

Edit 2 It works only if form is correctly filled...So no answer yet to my problem

Upvotes: 0

Views: 1049

Answers (1)

n_i_c_k
n_i_c_k

Reputation: 1534

What about a simple before filter. That way you don't have to mess with devise code

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

  def new
    super
  end

  private
    def check_conditions
      #your conditions
    end
end

Upvotes: 1

Related Questions