Reputation: 111
So I'm trying to get an error box to appear on my sign up page when the information has been entered incorrectly, however for some reason it comes up with a Template is missing error.
here is the full error message
Missing template users/create, application/create with {:handlers=>[:erb, :builder], :formats=>[:html], :locale=>[:en, :en]}. Searched in: * "/Users/chris/rails/demo_app/app/views"
It looks like it's trying to create a new file inside application called create but I'm not really sure why it's doing that?
here is my users_controller.rb
def new
@user = User.new
@title = "Sign up"
end
def create
@user = User.new(params[:user])
if @user.save
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
@title = "Sign up"
render = 'new'
end
end
end
Here's my _error_messages.html.erb
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %>
prohibited this user from being saved:</h2>
<p>There were problems with the following fields:</p>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
I'm not really sure what other files to list so if I have missed anything important please let me know!
Thanks :)
Chris
Upvotes: 0
Views: 106
Reputation: 7998
Render is a function, not an variable, so you don't want to say render = 'new'
, you want to pass the string 'new' into the render function, so render 'new'
should work just fine. This is the hard thing about learning Ruby, the lack of parentheses sometimes confuses people about variables and functions.
Upvotes: 1
Reputation: 10422
Instead of
render = 'new'
try to use:
render :action => 'new'
Upvotes: 1