Andrew
Andrew

Reputation: 3989

First argument in form cannot contain nil or be empty signup page

I'm following the Ruby on Rails tutorial, and I run into this error when I try to load the signup page:

Showing C:/Sites/rails_projects/sample_app/app/views/users/new.html.erb where line #6 raised: First argument in form cannot contain nil or be empty

<div class="row">
<div class="span6 offset3">
  <%= form_for (@user) do |f| %>     *this is the line 6 it's referring to*
    <%= render 'shared/error_messages' %>
    <%= f.label :name %>
    <%= f.text_field :name %>

Upvotes: 0

Views: 87

Answers (1)

CDub
CDub

Reputation: 13344

If you're going to use @user in form_for under the new action, you'll need to initialize @user in the new method of the UsersController.

class UsersController < ApplicationController

  def new
    @user = User.new
  end

end

An alternative would be to use User.new in the form itself, but that's generally not a best practice. Logic like that belongs in the controller.

Upvotes: 1

Related Questions