I’m using Rails 3.2.2 and am not getting the field_with_errors div when the validation fails.
views/sessions/new.html.erb
<%= form_tag sessions_path do %>
<p><%= label_tag :email %><br />
<%= email_field_tag :email %></p>
<p><%= label_tag :password %><br />
<%= password_field_tag :password %></p>
<p><%= submit_tag "Log in" %></p>
<% end %>
controllers/sessions_controller.rb
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password]) && user.account.subdomain == request.subdomain
session[:user_id] = user.id
redirect_to home_path
flash[:notice] = "Logged in!"
else
flash.now[:error] = "Invalid email or password"
render 'new'
end
end
models/user.rb
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation
has_secure_password
validates :email, :presence => true, :uniqueness => true
validates :password, :presence => true, :on => :create
I’m getting the flash message, but my view doesn’t render the field_with_errors wrapper divs if the validation fails. Any ideas?
Thanks.
It’s no longer included by default, you need to render your own error messages.
Here’s some sample code generated in a scaffold for a
Postmodel:You can then extract that into a partial for re-use with your other models.