ruby form_for password field not submitted to params hash -
working through ruby on rails tutorial hartl right now.
the password field displaying weirdly, , when submit information can see params hash doesn't display password key (but displays else). what's going on?
views/users/new.html.erb:
<h1> sign </h1> <div class = "row"> <div class = "col-md-6 col-md-offset-3"> <%= form_for(@user) |f| %> <%= render 'shared/error_messages' %> <%= f.label :name %> <%= f.text_field :name, class: 'form-control'%> <%= f.label :email %> <%= f.email_field :email, class: 'form-control'%> <%= f.label :password %> <%= password_field :password, class: 'form-control'%> <%= f.label :password_confirmation, "confirmation" %> <%= f.password_field :password_confirmation, class: 'form-control'%> <%= f.submit "create account", class: "btn btn-primary" %> <% end %> </div> </div>
controllers/users_controller.rb
class userscontroller < applicationcontroller before_action :logged_in_user, only: [:edit, :update] before_action :correct_user, only: [:edit, :update] def new @user = user.new end def show @user = user.find(params[:id]) end def create @user = user.new(user_params) if @user.save @user.send_activation_email flash[:info] = "please check email activate account." redirect_to root_url else render 'new' end end def edit @user = user.find(params[:id]) end def update @user = user.find(params[:id]) if @user.update_attributes(user_params) flash[:success] = "profile updated" redirect_to @user else render 'edit' end end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end def logged_in_user unless logged_in? store_location flash[:danger] = "please log in." redirect_to login_url end end def correct_user @user = user.find(params[:id]) redirect_to(root_url) unless current_user?(@user) end end
models/user.rb
class user < activerecord::base attr_accessor :remember_token, :activation_token, :reset_token before_save :downcase_email before_create :create_activation_digest validates :name, presence: true, length: { maximum: 50 } valid_email_regex = /\a[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { with: valid_email_regex}, uniqueness: { case_sensitive: false } has_secure_password validates :password, length: { minimum: 6 }, allow_blank: true def user.digest(string) cost = activemodel::securepassword.min_cost ? bcrypt::engine::min_cost : bcrypt::engine.cost bcrypt::password.create(string, cost: cost) end def user.new_token securerandom.urlsafe_base64 end def remember self.remember_token = user.new_token update_attribute(:remember_digest, user.digest(remember_token)) end def authenticated?(attribute, token) digest = send("#{attribute}_digest") return false if digest.nil? bcrypt::password.new(digest).is_password?(token) end def forget update_attribute(:remember_digest, nil) end # activates account. def activate update_attribute(:activated, true) update_attribute(:activated_at, time.zone.now) end # sends activation email. def send_activation_email usermailer.account_activation(self).deliver_now end # sets password reset attributes. def create_reset_digest self.reset_token = user.new_token update_attribute(:reset_digest, user.digest(reset_token)) update_attribute(:reset_sent_at, time.zone.now) end # sends password reset email. def send_password_reset_email usermailer.password_reset(self).deliver_now end def password_reset_expired? reset_sent_at < 2.hours.ago end private def downcase_email self.email = email.downcase end def create_activation_digest self.activation_token = user.new_token self.activation_digest = user.digest(activation_token) end end
<%= password_field :password, class: 'form-control'%>
to
<%= f.password_field :password, class: 'form-control'%>
Comments
Post a Comment