title: can't use @user in form_for in rails 4 getting a nil error
body: <p>I know that there are many questions a but every solution that i've tried did not work.
  I am trying to create a sign in form, but I am getting the following error 
  First argument in form cannot contain nil or be empty</p>
  
  <p>replacing <code>@user</code> with <code>User.new</code> will solve the error , but than I can't check for <code>@user.errors.any</code>..</p>
  
  <p>any suggestions?</p>
  
  <pre><code>&lt;h1&gt;Sign up&lt;/h1&gt;
  
  &lt;div class="row"&gt;
    &lt;div class="span6 offset7"&gt;
      &lt;%= form_for @user do |f| %&gt;
  
        &lt;% if @user.errors.any? %&gt;
          &lt;div id="error_explanation"&gt;
          &lt;h2&gt;&lt;%= pluralize(@user.errors.count, "error") %&gt; prohibited this user from being saved:&lt;/h2&gt;
          &lt;ul&gt;
            &lt;% @user.errors.full_messages.each do |msg| %&gt;
              &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
            &lt;% end %&gt;
          &lt;/ul&gt;
          &lt;/div&gt;
        &lt;% end %&gt;
  
  
        &lt;%= f.label :name %&gt;
        &lt;%= f.text_field :name %&gt;
  
        &lt;%= f.label :email %&gt;
        &lt;%= f.text_field :email %&gt;
  
        &lt;%= f.label :password %&gt;
        &lt;%= f.password_field :password %&gt;
  
        &lt;%= f.label :password_confirmation, "Confirmation" %&gt;
        &lt;%= f.password_field :password_confirmation %&gt;
        &lt;br&gt;
        &lt;%= f.submit "Create my account", class: "btn btn-large btn-primary" %&gt;
      &lt;% end %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and my controller code is</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_action :set_user, only: [:show]
  
    def new
          @user = User.new
    end
  
    # POST /user
    # POST /user.json
    def create
      @user = User.new(user_params)
  
      respond_to do |format|
        if @user.save
          format.html { redirect_to @user, notice: 'User was successfully created.' }
          format.json { render action: 'show', status: :created, location: @user }
        else
          format.html { render action: 'new' }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /user/1
    # PATCH/PUT /user/1.json
    def update
      respond_to do |format|
        if @user.update(user_params)
          format.html { redirect_to @user, notice: 'User was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
  
    def edit
    end
  
    # DELETE /user/1
    # DELETE /user/1.json
    def destroy
      @user.destroy
      respond_to do |format|
        format.html { redirect_to users_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_user
        @user = User.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def user_params
        params.require(:user).permit(:name, :email, :password)
      end
  
  
  end
  </code></pre>