3

I'm currently trying to build a simple form that takes an email address and puts it in the database as part of a landing page. The form is on home.html.erb and is controlled by the pages controller.

I'm getting the following error:

Missing template signup/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/me/rails_projects/this_project/app/views"

Here's my code:

home.html.erb has:

    <%= form_for(@signup) do |f| %>
        <div class="field">
            <%= f.text_field :email %>
        </div>

        <div class="actions">
            <%= f.submit "Sign up" %>
        </div>
    <% end %>

Pages controller has:

class PagesController < ApplicationController

  def home
    @title = "Title of my site"
    @signup = Signup.new
  end

end

Signups controller has:

class SignupController < ApplicationController

  def show
    @signup = Signup.new
  end

  def new
  end

  def create
    @signup = Signup.new(params[:signup])
    if @signup.save
    else
      render 'new'
    end
  end

end

Signup model has:

class Signup < ActiveRecord::Base

  attr_accessible :email

  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates(:email, :presence => true,
                    :length => {:maximum => 40},
                    :format => {:with => email_regex})

end

I'm not sure what's wrong but when I enter a valid email address in the field, this is the error I receive. I've googled around to no avail. Your help would be hugely appreciated.

1 Answer 1

3

It's telling you that a template is missing.

Typically, by default (if you don't call render() or redirect_to()) Rails renders the view associated with your action so in your case that would be: create.html.erb.

So you should redirect to something that makes more sense if you create a user successfully.

Like:

if @signup.save
   redirect_to :root
else
 #...
end

By the way I am assuming that you have configured the root path first, like this:

root :to => "something"

You'll redirect the user where it makes sense to your application.

1
  • That makes perfect sense. Thanks very much, Amokrane. Redirected them back to the signups page, my app now takes email addresses successfully! May 5, 2012 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.