在控制器中:
def createUserForHotel
@user=User.new(params_createUserForHotel)
if @user.save
flash[:notice]="New user is created for the hotel"
redirect_to(:controller=>'hotels',:action=>"createnewhotel")
else
flash[:notice]="New user not created "
redirect_to(:controller=>'hotels',:action=>"createnewhotel")
end
end
def params_createUserForHotel
params.require(:user).permit(:username,:password,:email,:hotel_id)
end
在迁移中:
def up
create_table :users do |t|
t.string "first_name",:limit=>25
t.string "last_name",:limit=>50
t.string "email",:null=>false,:limit=>100
t.string "username",:limit=>50
t.string "password",:limit=>40
t.integer "hotel_id"
t.timestamps
end
add_index("users","hotel_id")
end
class AlterUsers < ActiveRecord::Migration
def up
rename_column("users","password","hashed_password")
end
在Heroku日志中:
←[0m Started POST "/hotels/createUserForHotel" for 122.50.216.93 at 2014-11-16 10:18:16 +0000
←[36m2014-11-16T10:18:16.170638+00:00 app[web.1]:←[0m
←[36m2014-11-16T10:18:16.170641+00:00 app[web.1]:←[0m NoMethodError (undefined method password_digest=' for #<User:0x007f036c8ffe50>):
←[36m2014-11-16T10:18:16.170643+00:00 app[web.1]:←[0m app/controllers/hotels_controller.rb:140:in createUserForHotel'
←[36m2014-11-16T10:18:16.170644+00:00 app[web.1]:←[0m
我的应用在开发环境下运行得非常完美,但是在Heroku日志中出现了上述错误。我已经将我的应用部署到了Heroku。
bcrypt
宝石,同时在用户模式下你需要输入has_secure_password
。 - Ruby Racer