Heroku NoMethod错误,remember_token =

时间:2012-05-10 05:16:54

标签: ruby-on-rails heroku nomethoderror

我的应用程序在本地运行没有任何问题,但只要我将其推送到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>):

user.rb

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

user_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

1 个答案:

答案 0 :(得分:3)

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

您能验证该列是否在那里?

此外,您是否尝试过登录到heroku实例上的控制台会话:

heroku run bash --app my_app
bundle exec rails c

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