Note that there are some explanatory texts on larger screens.

plurals
  1. POMichael Hartl Tutorial v. 3.2 Chapter 7.17 NoMethodError in Users#new Line 4
    primarykey
    data
    text
    <p>After searching on this forum, I have found I'm at a standstill on this issue. I am running rails 3.2.1 and ruby 1.9.3</p> <p>I have followed the Hartl book very closely and am experiencing an error in testing and in rendering the signup page.</p> <p>Here is the error with some trace:</p> <pre><code>undefined method `model_name' for NilClass:Class Extracted source (around line #4): 1: &lt;% provide(:title, 'Sign up') %&gt; 2: &lt;h1&gt;Sign up&lt;/h1&gt; 3: 4: &lt;%= form_for(@user) do |f| %&gt; 5: &lt;div class="field"&gt; 6: &lt;%= f.label :name %&gt;&lt;br /&gt; 7: &lt;%= f.text_field :name %&gt; Rails.root: /Users/Brian/Sites/rails/brightspot_1-1 Application Trace | Framework Trace | Full Trace app/views/users/new.html.erb:4:in `_app_views_users_new_html_erb___4096651331723577149_70289685515940' </code></pre> <p>Here is my new.html.erb:</p> <pre><code>&lt;% provide(:title, 'Sign up') %&gt; &lt;h1&gt;Sign up&lt;/h1&gt; &lt;%= form_for(@user) do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :name %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :email %&gt;&lt;br /&gt; &lt;%= f.text_field :email %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :password_confirmation, "Confirmation" %&gt;&lt;br /&gt; &lt;%= f.password_field :password_confirmation %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Sign up" %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>And here is my users_controller.rb</p> <pre><code>class UsersController &lt; ApplicationController def show @user = User.find(params[:id]) end def new @user = User.new end def new end end </code></pre> <p>The test that is failing:</p> <pre><code>require 'spec_helper' describe "User pages" do subject { page } describe "profile page" do let(:user) { FactoryGirl.create(:user) } before { visit user_path(user) } it { should have_selector('h1', text: user.name) } it { should have_selector('title', text: user.name) } end describe "signup" do before { visit signup_path } describe "with invalid information" do it "should not create a user" do expect { click_button "Sign up" }.not_to change(User, :count) end end describe "with valid information" do before do fill_in "Name", with: "Example User" fill_in "Email", with: "user@example.com" fill_in "Password", with: "foobar" fill_in "Confirmation", with: "foobar" end it "should create a user" do expect { click_button "Sign up" }.to change(User, :count).by(1) end end end end </code></pre> <p>And the error messages from rspec:</p> <pre><code>Failures: 1) User pages signup with invalid information should not create a user Failure/Error: before { visit signup_path } ActionView::Template::Error: undefined method `model_name' for NilClass:Class # ./app/views/users/new.html.erb:4:in `_app_views_users_new_html_erb___947544063866573638_70125101083220' # ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in &lt;top (required)&gt;' 2) User pages signup with valid information should create a user Failure/Error: before { visit signup_path } ActionView::Template::Error: undefined method `model_name' for NilClass:Class # ./app/views/users/new.html.erb:4:in `_app_views_users_new_html_erb___947544063866573638_70125101083220' # ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in &lt;top (required)&gt;' Finished in 0.20414 seconds 2 examples, 2 failures </code></pre> <p>Any help with this would be much appreciated. Thanks in advance, Brian.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload