0

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

titibouboul
  • 1,348
  • 3
  • 16
  • 30
  • http://stackoverflow.com/questions/5167576/whitelisting-with-devise – Cristian Bica Aug 15 '13 at 21:35
  • I've seen this post but I don't understand the voted answer: what's the function name to create account for user ? – titibouboul Aug 15 '13 at 21:51
  • This question is a bit under-specified. You could use validations on a model, a before_filter on the controller, lots of things, depending on (1) what you want to check and (2) what you want to prevent from happening if the conditions fail. Do you just not want the `#create` action to succeed? Do you want to not even show the registration form unless the conditions are satisfied? Much more information is needed to give a reasonable answer. – gregates Aug 15 '13 at 22:55
  • @titibouboul what do you mean by "It works only if form is correctly filled" ? – alf Aug 20 '13 at 15:33
  • It means that if forms is filled uncorrectly, it redirect from "/users/sign_up?token=xxxxx" to "/users", then params["token"] does not exist anymore – titibouboul Aug 20 '13 at 16:19

1 Answers1

1

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
n_i_c_k
  • 1,504
  • 10
  • 18