ruby form_for password field not submitted to params hash

nachime

Working through the ruby on rails tutorial from Hartl right now. enter image description here

the password field is displaying weirdly, and when I submit some information I can see that my params hash doesn't display a password key (but displays everything else). What's going on?

views/users/new.html.erb:

<h1> Sign up </h1>
<div class = "row">
    <div class = "col-md-6 col-md-offset-3">
        <%= form_for(@user) do |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 my 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 your email to activate your 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 an 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 the 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
sethi
<%= password_field :password, class: 'form-control'%>

to

<%= f.password_field :password, class: 'form-control'%>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Rails: form_for with field for Hash

From Dev

Ruby on Rails - Send two text_field_tag values present inside form_for in hash format

From Dev

Ruby array to hash with params

From Dev

Passing extra params through text_field_tag in form_for

From Dev

Passing extra params through text_field_tag in form_for

From Dev

Include field in Rails user form, but not in params[:user] hash

From Dev

Ruby on Rails 4 - Form helper not passing a params hash to controller

From Dev

Rails: In a controller, add a value to the params submitted by a form

From Dev

Changing the ActiveModel submitted by a form_for

From Dev

Validating OpenCart password hash in ruby

From Dev

Validating OpenCart password hash in ruby

From Dev

Ruby on Rails: Getting the value from a select form field before it's submitted

From Dev

Modify ruby hash in place( rails strong params)

From Dev

Ruby on rails - read and evaluate params hash

From Dev

ruby on rails params hash and it's contents

From Dev

remove the key and value in the params hash with ruby on rails

From Dev

form_for - Ruby on Rails

From Dev

Ruby form_for explanation?

From Dev

What are the security implications of having submitted password in username field?

From Dev

Preventing an HTML form field from being submitted

From Dev

pass in password_hash field with pdo

From Dev

Send form params hash as response content

From Dev

Affecting resulting params set from form_for

From Dev

Rails form_for pass params as Array

From Dev

Retrieve hidden field in form_for

From Dev

nested ruby params hash and radio buttons dont play along well

From Dev

Rails Save Hash in Model Attribute Submitted by Simple Form

From Dev

Ruby - Finding the data in specific field/key of hash

From Dev

Django how to get password after registration form is submitted?

Related Related

  1. 1

    Rails: form_for with field for Hash

  2. 2

    Ruby on Rails - Send two text_field_tag values present inside form_for in hash format

  3. 3

    Ruby array to hash with params

  4. 4

    Passing extra params through text_field_tag in form_for

  5. 5

    Passing extra params through text_field_tag in form_for

  6. 6

    Include field in Rails user form, but not in params[:user] hash

  7. 7

    Ruby on Rails 4 - Form helper not passing a params hash to controller

  8. 8

    Rails: In a controller, add a value to the params submitted by a form

  9. 9

    Changing the ActiveModel submitted by a form_for

  10. 10

    Validating OpenCart password hash in ruby

  11. 11

    Validating OpenCart password hash in ruby

  12. 12

    Ruby on Rails: Getting the value from a select form field before it's submitted

  13. 13

    Modify ruby hash in place( rails strong params)

  14. 14

    Ruby on rails - read and evaluate params hash

  15. 15

    ruby on rails params hash and it's contents

  16. 16

    remove the key and value in the params hash with ruby on rails

  17. 17

    form_for - Ruby on Rails

  18. 18

    Ruby form_for explanation?

  19. 19

    What are the security implications of having submitted password in username field?

  20. 20

    Preventing an HTML form field from being submitted

  21. 21

    pass in password_hash field with pdo

  22. 22

    Send form params hash as response content

  23. 23

    Affecting resulting params set from form_for

  24. 24

    Rails form_for pass params as Array

  25. 25

    Retrieve hidden field in form_for

  26. 26

    nested ruby params hash and radio buttons dont play along well

  27. 27

    Rails Save Hash in Model Attribute Submitted by Simple Form

  28. 28

    Ruby - Finding the data in specific field/key of hash

  29. 29

    Django how to get password after registration form is submitted?

HotTag

Archive