title: integrating a homemade captcha to sign up and sign in?
body: <p>So I have a basic sign up, sign in site with username and password. I don't want to use recaptcha and was wondering whether i can create my own? 
  So have for example 'what colour is an orange'. </p>
  
  <p>I was wondering how you could integrate this (if you can that is) into the form_for as it wouldn't be part of the @user object and throws an error.</p>
  
  <p>Here is the controller</p>
  
  <pre><code>def new
   @user = User.new
   @captcha = Captcha.find(rand(1..3))
  end
  
  def create
   @user = User.new(user_params)
   if @user.save
    session[:user_id] = @user.id
    redirect_to root_path
   else
    render 'new'
   end
  end
  
  private
  
  def user_params
   params.require(:user).permit(:username, :password, :release_pin)
  end
  </code></pre>
  
  <p>Here is the view</p>
  
  <pre><code>    &lt;div class="sign-in-form"&gt;
        &lt;%= form_for @user do |form| %&gt;
          &lt;div class="form-text"&gt;
            &lt;%= form.label :username %&gt; &lt;br&gt;
            &lt;%= form.text_field :username %&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div class="form-text"&gt;
            &lt;%= form.label :password %&gt; &lt;br&gt;
            &lt;%= form.text_field :password %&gt;
          &lt;/div&gt;
          &lt;br&gt;
  
       ############## this here obviously throws 
       an error but this is the kind of thing i would want #########
  
  
          &lt;div class="form-text"&gt;
            &lt;p&gt; &lt;%=@captcha.question%&gt; &lt;/p&gt;   
            &lt;%= form.text_field :captcha_answer %&gt;
          &lt;/div&gt;
  
          &lt;div class="form-text"&gt;
            &lt;%= form.submit "Submit" %&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>I've looked into nested forms but don't think that's the correct answer... but I could wrong as I'm only a beginner. thanks</p>