gpt4 book ai didi

ruby-on-rails - Heroku NoMethoderror, remember_token=

转载 作者:行者123 更新时间:2023-12-04 20:51:07 25 4
gpt4 key购买 nike

我的应用程序在本地运行没有任何问题,但是一旦我将它推送到 Heroku,日志就会显示 NoMethodError。查看我的代码,我并没有立即看到我错过了什么。特别是,为什么它会在本地工作,但在 Heroku 上会抛出 NoMethod?

错误

Started POST "/users" for <IP>
Processing by UsersController#create as HTML
Completed 500 Internal Server Error in 102ms

app/models/user.rb:38:in `create_remember_token'
app/controllers/users_controller.rb:28:in `create'

NoMethodError (undefined method `remember_token=' for #<User:0x000000052e8fb0>):

用户名
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation, :image
has_secure_password
has_many :microposts, dependent: :destroy
mount_uploader :image, AvatarUploader

before_save { |user| user.email = email.downcase }
before_save :create_remember_token

validates :name, presence: true,
length: { maximum: 50}
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }

validates :password, length: {minimum: 6}
validates :password_confirmation, presence: true


private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end

用户 Controller .rb
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: :destroy


def index
@users = User.paginate(page: params[:page])
end

def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end

def new
@user = User.new
end

def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
redirect_to users_path
end

def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to El Beano"
redirect_to @user
else
render 'new'
end
end

def edit
@user = User.find(params[:id])
end

def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = 'Profile updated'
sign_in @user
redirect_to @user
else
render 'edit'
end
end

private


def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end

def admin_user
redirect_to(root_path) unless current_user.admin?
end
end

最佳答案

看起来您已将代码上传到 Heroku,但创建该列的数据库迁移未运行或未正确运行。

您能验证该列是否存在吗?

另外,您是否尝试过在您的 heroku 实例上登录控制台 session :

heroku run bash --app my_app
bundle exec rails c

然后测试您是否可以在该环境中访问该属性?

关于ruby-on-rails - Heroku NoMethoderror, remember_token=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527892/

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