Rails:部署到Heroku,有很多问题

我第一次尝试将我的rails应用程序部署到Heroku,遇到了很多问题。 该应用程序崩溃,您可以查看图像中的日志: http : //i.stack.imgur.com/bsx1b.png

更糟糕的是,当我试图在本地查看我的应用程序时,它无法在postgreSQL环境中工作。当我回到在database.yml中使用sqLite3时工作正常。 我认为问题可能是我实际上必须安装postgreSQL,除了添加pg gem和运行bundle install。

我继续使用一键安装程序(Windows 7 64位)安装PostgreSQL。 重启后,一个简单的rails服务器或bundle install命令开始失败,所以我重新安装了整个ruby和rails。

现在rails server命令工作正常,当我尝试在本地环境中查看我的应用程序时,它会提示不同的错误。 所以现在我有pgAdmin III和Rails

PG::Error fe_sendauth: no password supplied 

我试着遵循这个 ,但我找不到“pg_hba.conf”。 我想答案是基于不同的操作系统。

现在再次,捆绑器不工作,给我错误……

问题: 1)使用一键安装程序安装postgreSQL是否正确? 因为这导致我的ROR以某种方式“崩溃”,我不得不重新安装rails。 2)我想我将删除与postgreSQL相关的所有内容,重新安装Rails,并从头开始。 我必须采取哪些步骤? 我看过的所有参考文献似乎都不适合Windows环境。

在我的gemfile中,我有

 gem 'pg' gem 'thin' 

在我的数据库中,我有

 # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: postgresql encoding: utf8 database: mangfeel_development pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: postgresql encoding: utf8 database: mangfeel_test pool: 5 timeout: 5000 production: adapter: postgresql encoding: utf8 database: mangfeel_production pool: 5 timeout: 5000 

安装PostgreSQL后,我现在遇到的错误:

 c:\ruby\myapp>rails server C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:926:in `report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError) from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:244:in `activate_dep' from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:236:in `activate' from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:1307:in `gem' from C:/RailsInstaller/Ruby1.9.3/bin/rails:18:in `' 

当我运行bundle install时:

 Gem::InstallError: The 'json' native gem requires installed build tools Please update your PATH to include build tools or download the DevKit from 'http://rubyinstaller.org/downloads' and follow the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit' An error occurred while installing json (1.7.5), and Bundler cannot continue. Make sure that `gem install json -v '1.7.5'` succeeds before bundling. 

所以我将完全删除pgAdminIII,PostgreSQL,Ruby on Rails,并从头开始。

我认为部署并不会那么困难,但是从SQLite3迁移到PostgreSQL比我想象的要花费更多的时间和精力。 我真的很感激这个问题的一些帮助。

————————————————– ————————————————– ——————–

更新:重新安装一切后,我将再次进行设置。

我检查了我的SQLite3版本应用程序运行正常。 所以我开始设置postgreSQL。 我第一次设置postgreSQL时遇到以下错误。 通过设置,我的意思是编辑config / database.yml并安装gem’pg’并删除gem的sqlite3。 当我尝试连接到localhost:3000时,出现以下错误:

 ActiveRecord::ConnectionNotEstablished 

经过一些研究,我发现设置数据库可能会有更多步骤。 所以我运行了bundle命令,

 bundle exec rake db:setup 

但是在控制台中,当我运行bundle exec rake db:setup时出现以下错误。

 Couldn't create database for {"adapter"=>"postgresql", "host"=>"localhost", "encoding"=>"utf8", "database"=>"db/myapp_test", "pool"=>5, "timeout"=>5000} rake aborted! could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? c:/ruby/myapp/config/environment.rb:5:in `' Tasks: TOP => db:schema:load => environment 

当我尝试连接到localhost:3000时,我再次得到了上述错误,而不是ActiveRecord :: ConnectionNotEstablished

问题:我做错了什么,如何解决问题?

如果您有错误:

 PG::Error fe_sendauth: no password supplied 

您有好消息,您的应用程序现在可以使用PostgreSQL数据库。 (但你需要配置一些东西)

安装PostgreSQL后,您可以通过命令使用PostgreSQL创建新的rails应用程序:

 rails new my_app -d postgresql 

这将是database.yml将被创建:

 development: adapter: postgresql encoding: unicode database: my_app_development pool: 5 username: my_app password: test: adapter: postgresql encoding: unicode database: my_app_test pool: 5 username: my_app password: production: adapter: postgresql encoding: unicode database: my_app_production pool: 5 username: my_app password: 

你看,三个数据库都有usernamepassword字段,这是Postgresql中的帐户用户, database.yaml文件中的三个数据库将由该用户创建。 所以你需要提供usernamepassword 。 安装Postgresql后默认,它创建了一个用户名是postgresql的用户,密码是postgresql 。 你可以使用它。

如果您想使用其他用户,只需打开pgAdmin III并通过右键单击Login Roles创建新用户,然后选择New login role以创建具有密码的新用户。 然后将该用户名和密码放入database.yaml文件。

之后,您现在需要的只是找到并打开pg_hba.conf文件,以便为app配置一些可以使用PostgreSQL。 我很长时间没有使用Windows,所以我不知道它在哪里,但你可以在文件夹中找到你安装的PostgreSQL。 例如,如果您在E:\ partition上安装,也许您可​​以在以下位置找到它:

E:\PostgreSQL\version\data

找到后,打开并找到一行:

 # "local" is for Unix domain socket connections only local all all ident sameuser 

将其更改为:

 # "local" is for Unix domain socket connections only local all all md5 

然后重新启动Postgresql数据库。 要为app创建数据库,请运行rake db:createrake db:create:all 。 现在你的应用程序现在可以使用PostgreSQL数据库,非常高兴:)。

我不是Rails的专家,但这是我最近部署的一个YAML文件,我在带有POSTGRES的heroku上做了

 development: adapter: postgresql host: localhost database: dbname_development production: adapter: postgresql host: localhost database: dbname_production 

在postgres部署的情况下,您似乎缺少一个名为host的参数

在Windows上从SQLite3移动到PostgreSQL的步骤,以便将现有Rails应用程序部署到Heroku:

  1. 在你的Gemfile中 ,找到gem’sqlite3 gem 'sqlite3'并将其更改为gem’pg gem 'pg' 。 运行bundle install
  2. 从这里下载Postgres。 选择一键安装程序并选择您的操作系统环境(32位或64位)。 在安装过程中,请勿选择安装它建议您安装的任何其他软件。 它可能会搞乱你现有的Rails,你将不得不重新安装Rails。
  3. 现在转到config / database.yml,并将其更改为以下格式。 当前的一个是为SQLite3设置的,并且缺少PostgreSQL所需的一些字段。

     development: adapter: postgresql encoding: unicode database: my_app_development pool: 5 username: my_app password: test: adapter: postgresql encoding: unicode database: my_app_test pool: 5 username: my_app password: production: adapter: postgresql encoding: unicode database: my_app_production pool: 5 username: my_app password: 

适配器不同,有用户名和密码字段。 默认用户名和密码是postgresql,但是如果它不起作用(它对我不起作用),那么转到你的pgAdmin,创建一个新的登录角色来制作另一个用户名/密码(选中使其成为一个用户名/密码的选项)超级用户)并使用它。

4,此时,您可以通过运行创建新的应用程序

 rails new my_app -d postgresql 

运行本地服务器,并尝试连接到localhost:3000以查看是否显示欢迎页面。

5,如果一切正常,那么您需要做的就是创建一个新的PostgreSQL数据库,并将现有模型迁移到它。 跑

 rake db:create:all rake db:migrate 

完成! 现在检查您现有的应用程序是否在本地运行正常,并尝试将您的应用程序部署到Heroku。