gpt4 book ai didi

ruby-on-rails - NoMethodError(# 的未定义方法 `password_digest='

转载 作者:行者123 更新时间:2023-12-03 00:30:16 25 4
gpt4 key购买 nike

在 Controller 中:

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 中部署了我的应用程序。

最佳答案

您的password列应命名为password_digest - 而不是hashed_pa​​sswordpassword

关于ruby-on-rails - NoMethodError(#<User> 的未定义方法 `password_digest=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26956231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com