Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:42:08+00:00 2026-06-05T06:42:08+00:00

I am trying to use a model altered to support bcrypt password, like so

  • 0

I am trying to use a model altered to support bcrypt password, like so

require 'bcrypt'
class User < ActiveRecord::Base
  # users.password_hash in the database is a :string
  include BCrypt

  def password
    @password ||= Password.new(password_hash)
  end

  def password=(new_password)
    @password = Password.create(new_password)
    self.password_hash = @password
  end
end

I added this in AFTER the scaffolding, hoping that the password and password= was enough to keep it going, using this, However it is not working, the form_for() etc wont work and I get the error:

ActionView::Template::Error (invalid hash):
2012-06-07T12:45:20+00:00 app[web.1]:     17:   </div>
2012-06-07T12:45:20+00:00 app[web.1]:     18:   <div class="field">
2012-06-07T12:45:20+00:00 app[web.1]:     19:     <%= f.label :password %><br />
2012-06-07T12:45:20+00:00 app[web.1]:     20:     <%= f.text_field :password %>
2012-06-07T12:45:20+00:00 app[web.1]:     21:   </div>
2012-06-07T12:45:20+00:00 app[web.1]:     22:   <div class="field">
2012-06-07T12:45:20+00:00 app[web.1]:     23:     <%= f.label :email %><br />

Does anyone know how I can make this work, I am new to Rails

This is On the New Function
Full backtrace as requested:

2012-06-12T18:23:57+00:00 app[web.1]: ActionView::Template::Error (invalid hash):
2012-06-12T18:23:57+00:00 app[web.1]:     19:     <%= f.label :password %><br />
2012-06-12T18:23:57+00:00 app[web.1]:     18:   <div class="field">
2012-06-12T18:23:57+00:00 app[web.1]:     17:   </div>
2012-06-12T18:23:57+00:00 app[web.1]:     20:     <%= f.text_field :password %>
2012-06-12T18:23:57+00:00 app[web.1]:     22:   <div class="field">
2012-06-12T18:23:57+00:00 app[web.1]:     23:     <%= f.label :email %><br />
2012-06-12T18:23:57+00:00 app[web.1]:   app/models/user.rb:19:in `new'
2012-06-12T18:23:57+00:00 app[web.1]:     21:   </div>
2012-06-12T18:23:57+00:00 app[web.1]:   app/models/user.rb:19:in `password'
2012-06-12T18:23:57+00:00 app[web.1]:   app/views/users/_form.html.erb:20:in `block in _app_views_users__form_html_erb__2064609863987267967_31546180'
2012-06-12T18:23:57+00:00 app[web.1]:   app/views/users/_form.html.erb:1:in `_app_views_users__form_html_erb__2064609863987267967_31546180'
2012-06-12T18:23:57+00:00 app[web.1]:   app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___1991359801167056023_31763940'
2012-06-12T18:23:57+00:00 app[web.1]:   app/controllers/users_controller.rb:251:in `new'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:42:10+00:00Added an answer on June 5, 2026 at 6:42 am

    The exception message “invalid hash” indicates that your view is working just fine, but User#password fails for whatever reason. Perhaps user doesn’t have a password_hash defined (ie, it is nil, “”, or some other invalid value), causing Password.new to error out?

    Looking at your backtrace seems to reinforce this:

    2012-06-12T18:23:57+00:00 app[web.1]:   app/models/user.rb:19:in `new'
    2012-06-12T18:23:57+00:00 app[web.1]:   app/models/user.rb:19:in `password'.
    

    The error occurs in user.rb when calling new inside your password method. Thus I am guessing line #19 is

    @password ||= Password.new(password_hash)
    

    So it looks like Password.new does not like the value of password_hash for some reason. Exactly why, I can only guess at.

    • What exactly is Password?
    • What is the value of password_hash?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use PHP ActiveRecord in Codeigniter. I have a model like this:
I'm trying to use Hash object like as ActiveRecord Model within FormHelper: <% hash
I am trying to use nested attributes on my user model for settings so
I'm trying to use a User model inheritance in my django application. Model looks
I'm trying to use Dynamic Data with a entity model that has Abstract class
I'm trying to use SQLAlchemy to implement a basic users-groups model where users can
I'm trying to use the same class, a class extends play.db.jpa.Model, in rabbitmq and
Im trying to use printf in my assembley code in model large, and i
I'm trying to use the R caret module for model generation and I want
I'm trying to use an event dispatcher to allow a model to notify subscribed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.