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.
It’s telling you that a template is missing.
Typically, by default (if you don’t call
render()orredirect_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:
By the way I am assuming that you have configured the root path first, like this:
You’ll redirect the user where it makes sense to your application.