我已经在 heroku 上部署并运行命令 heroku open。它在浏览器中打开正常。但是当我点击一个注册按钮时,它会停止并给出以下 heroku 日志。它在本地服务器上完美运行。但我也想在heroku服务器上运行。这是http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:signin_success的示例
2012-05-11T12:24:58+00:00 app[web.1]: Started GET "/users/new" for 122.179.134.45 at 2012-05-11 05:24:58 -0700
2012-05-11T12:24:58+00:00 app[web.1]: Processing by UsersController#new as HTML
2012-05-11T12:24:58+00:00 app[web.1]: Completed 500 Internal Server Error in 37ms
2012-05-11T12:24:58+00:00 app[web.1]:
2012-05-11T12:24:58+00:00 app[web.1]: : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
2012-05-11T12:24:58+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR: relation "users" does not exist
2012-05-11T12:24:58+00:00 app[web.1]: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
2012-05-11T12:24:58+00:00 app[web.1]: WHERE a.attrelid = '"users"'::regclass
2012-05-11T12:24:58+00:00 app[web.1]: FROM pg_attribute a LEFT JOIN pg_attrdef d
2012-05-11T12:24:58+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped
2012-05-11T12:24:58+00:00 app[web.1]: ORDER BY a.attnum
2012-05-11T12:24:58+00:00 app[web.1]: ):
2012-05-11T12:24:58+00:00 heroku[router]: GET demoapp3708.heroku.com/users/new dyno=web.1 queue=0 wait=0ms service=44ms status=500 bytes=643
2012-05-11T12:24:58+00:00 app[web.1]: app/controllers/users_controller.rb:8:in `new'
2012-05-11T12:24:58+00:00 app[web.1]: app/controllers/users_controller.rb:8:in `new'
Gemfile如下:
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.2'
gem 'jquery-rails', '2.0.0'
#We’ll use the state-of-the-art hash function called bcrypt to irreversibly encrypt the password to form the password hash.
gem 'bcrypt-ruby', '3.0.1'
gem 'pg', '0.13.2'
group :development do
gem 'rspec-rails', '2.9.0'
gem 'guard-rspec', '0.5.5'
gem 'capybara', '1.1.2'
gem 'annotate', '~> 2.4.1.beta'
gem 'sqlite3', '1.3.6'
end
group :test do
gem 'rspec-rails', '2.9.0'
gem 'capybara', '1.1.2'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'factory_girl_rails', '1.4.0'
#gem 'webrat', '0.7.1'
end
group :assets do
# gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'sass-rails', '~> 3.2.4'
gem 'coffee-rails', '~> 3.2.2'
gem 'uglifier', '>= 1.2.3'
end
app/controllers/users_controller.rb 是:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
end
在 heroku 运行 rake db:migrate
PG::Error: ERROR: relation "users" does not exist
: ALTER TABLE "users" ADD COLUMN "password_digest" character varying(255)