Note that there are some explanatory texts on larger screens.

plurals
  1. POForm errors not showing in Ruby on Rails
    primarykey
    data
    text
    <p>I'm trying to create a registration form with Rails. It's working, but it doesn't displays the errors from the validation (it validates, but the errors don't display).</p> <p>Here are my files:</p> <pre><code># new.html.erb &lt;h1&gt;New user&lt;/h1&gt; &lt;% form_for :user, :url =&gt;{:action=&gt;"new", :controller=&gt;"users"} do |f| %&gt; &lt;%= f.error_messages %&gt; &lt;p&gt; &lt;%= f.label :name %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.submit 'Create' %&gt; &lt;/p&gt; &lt;% end %&gt; &lt;%= link_to 'Back', users_path %&gt; </code></pre> <hr> <pre><code># user.rb class User &lt; ActiveRecord::Base validates_presence_of :name validates_presence_of :password end </code></pre> <hr> <pre><code>#users_controller.rb class UsersController &lt; ApplicationController def index @users = User.all end def show @user = User.find(params[:id]) end def new if session[:user_id].nil? if params[:user].nil? #User hasn't filled the form @user = User.new else #User has filled the form user = User.new(params[:user]) if user.save user.salt = rand(1000000000) user.password = Digest::MD5.hexdigest(user.salt.to_s + user.password) user.save flash[:notice] = 'User was successfully created.' session[:user_id] = user.id session[:password] = user.password redirect_to url_for(:action=&gt;"index",:controller=&gt;"users") else render :action=&gt;"new" end end else #User is already logged in flash[:notice] = 'You are already registered.' redirect_to url_for(:action=&gt;"index") end end # some other actions removed.... end </code></pre> <hr> <p>Why aren't the errors being displayed?</p> <p>Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload