Note that there are some explanatory texts on larger screens.

plurals
  1. POpassword validation form in rails
    primarykey
    data
    text
    <p>I'm new to rails and i want to make a signup login and forget password functionality from scratch so i have been following railscast 250 and 274 episodes..so the problem is, the validations on password and password confirmation fields are working fine on signup form but on the reset password form those validations are not working at all..code is below</p> <p>model: </p> <pre><code> class User &lt; ActiveRecord::Base attr_accessible :email, :password, :password_confirmation, :signup_token attr_accessor :password before_save :encrypt_password before_create {generate_token(:auth_token)} before_create {generate_token(:signup_token)} validates :password, length: {minimum: 8}, confirmation: true, presence: true,:on =&gt; :create validates :email, presence: true, uniqueness: true validates :email, format: {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "not valid"} def generate_token(column) begin self[column] = SecureRandom.urlsafe_base64 end while User.exists?(column =&gt; self[column]) end def self.authenticate(email, password) user = find_by_email(email) if user &amp;&amp; user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt) &amp;&amp; user.active == true user else nil end end def encrypt_password if password.present? self.password_salt = BCrypt::Engine.generate_salt self.password_hash = BCrypt::Engine.hash_secret(password, password_salt) end end def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = Time.zone.now save! UserMailer.password_reset(self).deliver end end </code></pre> <p>password_resets_controller:</p> <pre><code> class PasswordResetsController &lt; ApplicationController def new end def create user = User.find_by_email(params[:email]) user.send_password_reset if user redirect_to root_url, :notice =&gt; "Email sent with password reset instructions." end def edit @user = User.find_by_password_reset_token!(params[:id]) end def update @user = User.find_by_password_reset_token!(params[:id]) if @user.password_reset_sent_at &lt; 2.hours.ago redirect_to new_password_reset_path, :alert =&gt; "Password reset has expired." elsif @user.update_attributes(params[:user]) redirect_to root_url, :notice =&gt; "Password has been reset." else render :edit end end end </code></pre> <p>and views under password reset are new.html.erb:</p> <pre><code> &lt;h1&gt;Reset Password&lt;/h1&gt; &lt;%= form_tag password_resets_path, :method =&gt; :post do %&gt; &lt;div class="field"&gt; &lt;%= label_tag :email %&gt; &lt;%= text_field_tag :email, params[:email] %&gt; &lt;/div&gt; &lt;div class="actions"&gt;&lt;%= submit_tag "Reset Password" %&gt;&lt;/div&gt; &lt;% end %&gt; </code></pre> <p>edit.html.erb:</p> <pre><code> &lt;h1&gt;Reset Password&lt;/h1&gt; &lt;%= form_for @user, :url =&gt; password_reset_path(params[:id]) do |f| %&gt; &lt;% if @user.errors.any? %&gt; &lt;div class="error_messages"&gt; &lt;h2&gt;Form is invalid&lt;/h2&gt; &lt;ul&gt; &lt;% for message in @user.errors.full_messages %&gt; &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :password %&gt; &lt;%= f.password_field :password %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :password_confirmation %&gt; &lt;%= f.password_field :password_confirmation %&gt; &lt;/div&gt; &lt;div class="actions"&gt;&lt;%= f.submit "Update Password" %&gt;&lt;/div&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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