新手问题 新手求助,关于 has_secure_password

drine · 2015年03月06日 · 最后由 drine 回复于 2015年03月06日 · 3512 次阅读

为什么 model 里只要添加了 has_secure_password,执行 User.all 就无法取出里面的数据呢?

自己搜了下没找到答案..所以才来问

数据库里面有 password_digest 字段吗

来自 RubyChina4Android

贴错误日志。

You don't have bcrypt-ruby installed in your application. Please add it to your Gemfile and run bundle install Gem::LoadError: can't activate bcrypt-ruby (~> 3.1.2), already activated bcrypt- ruby-3.0.1-x86-mingw32. Make sure all dependencies are added to Gemfile. from D:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.8.2/lib/bundler/rubyg ems_integration.rb:271:in block in replace_gem' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_mo del/secure_password.rb:47:inhas_secure_password' from C:/Users/Administrator/sample_app/app/models/user.rb:8:in <class:U ser>' from C:/Users/Administrator/sample_app/app/models/user.rb:1:in' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:424:in load' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:424:inblock in load_file' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:616:in new_constants_in' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:423:inload_file' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:324:in require_or_load' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:463:inload_missing_constant' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_ support/dependencies.rb:184:in const_missing' from (irb):1 from D:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/comman ds/console.rb:90:instart' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/comman ds/console.rb:9:in start' from D:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/comman ds.rb:62:in' from bin/rails:4:in require' from bin/rails:4:in'irb(main):003:0>

 def change
    add_column :users, :password_digest, :string
  end
end

这是我最新迁移的数据库,执行了 bundle exec rake db:migrate。

source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'

# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3' , '1.3.8'
gem 'rspec-rails' , '2.13.1'
end
group :test do
gem 'selenium-webdriver' , '2.35.1'
gem 'capybara' , '2.1.0'
end

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc','0.3.20', require: false
end
group :production do
gem 'pg' , '0.15.1'
end

gem 'bootstrap-sass' , '2.3.2.0'
gem 'bcrypt-ruby' , '3.0.1'
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

我有这个 bcrypt-ruby 在 gemfile 里啊,是版本问题么?

You don't have bcrypt-ruby installed in your application. Please add it to your Gemfile and run bundle install

#8 楼 @huobazi gem 'bcrypt-ruby' , '3.0.1' 我 gemfile 里有这个啊。

#9 楼 @drine 意思是让你

run

bundle install

#10 楼 @lgn21st 执行过的啊..

#2 楼 @slim 有这个字段,我执行了迁移的。

用 3.1.2 就解决了,版本的问题原来是。

谢谢各位啦。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号