Hartl Ruby-on-Rails Tutorial (3.2), Section 7.2 - Sign up form missing template
ruby-on-rails
Solution
Short Answer:
It is not supposed to work (yet). Continue the tutorial, the answer will come in section 7.4;
Slightly longer Answer:
When you fill in the form and push the submit-button, the create-event in the users_controller gets triggered. Since you don't have any code there (yet), Rails assumes that you just want to render `create.html.erb`, which doesn't exist (and never will). In order to get this to work immediately, you have to add `redirect_to @user` right underneath `if @user.save`. Check Listing 7.25;
Problem
I'm getting the following error when testing the sign up page for the ruby-on-rails tutorial: ``` Failures: 1) User pages signup with valid information should create a user Failure/Error: expect { click_button submit }.to change(User, :count).by(1) ActionView::MissingTemplate: Missing template users/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/Fif/rails_projects/sample_app/app/views" # (eval):2:in `click_button' # ./spec/requests/user_pages_spec.rb:43:in `block (5 levels) in <top (required)>' # ./spec/requests/user_pages_spec.rb:43:in `block (4 levels) in <top (required)>' Finished in 0.76918 seconds 35 examples, 1 failure Failed examples: rspec ./spec/requests/user_pages_spec.rb:42 # User pages signup with valid information should create a user ``` I'm not sure what the problem is, and I've gone over the code several times to make sure that it matches the examples in the book. I'm pretty sure that it has to do with the new.html.erb file user_pages_spec.rb ``` require 'spec_helper' describe "User pages" do subject { page } describe "signup page" do before { visit signup_path } it { should have_selector('h1', text: 'Sign up') } it { should have_selector('title', text: full_title('Sign up')) } end 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 } let(:submit) { "Create my account" } describe "with invalid information" do it "should not create a user" do expect { click_button submit }.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 submit }.to change(User, :count).by(1) end end end end ``` new.html.erb ``` <%= provide(:title, 'Sign up') %> <h1>Sign up</h1> <div class="row"> <div class="span6 offset3"> <%= form_for(@user) do |f| %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :email %> <%= f.text_field :email %> <%= f.label :password %> <%= f.password_field :password %> <%= f.label :password_confirmation, "Confirmation" %> <%= f.password_field :password_confirmation %> <%= f.submit "Create my account", class: "btn btn-large btn-primary" %> <% end %> </div> </div> ``` users_controller.rb ``` class UsersController < ApplicationController def show @user = User.find(params[:id]) end def new @user = User.new end def create @user = User.new(params[:user]) if @user.save # Handle a successful save. else render 'new' end end end ```