Rails:部署到Heroku,存在许多问题 [英] Rails: Deploying to Heroku, Many Problems

查看:67
本文介绍了Rails:部署到Heroku,存在许多问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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




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

Trying to deploy my rails app to Heroku for the first time, I ran into many problems. The app crashed, and you can look at the logs in the image: http://i.stack.imgur.com/bsx1b.png

Even worse, when I tried to look at my application locally, it failed to work on postgreSQL environment.It worked fine when I went back to use sqLite3 in database.yml. I thought the problem might be that I actually have to install postgreSQL, in addition to adding pg gem and running bundle install.

我继续使用以下命令安装PostgreSQL:单击安装程序(Windows 7 64位)。重新启动后,一个简单的Rails服务器或捆绑软件安装命令开始失败,因此我重新安装了整个ruby&

I went ahead to install PostgreSQL with the one-click installer (Windows 7 64bit). After reboot, a simple rails server or bundle install commands started failing, so I reinstalled the entire ruby & rails.

现在rails服务器命令可以正常工作,当我尝试在本地环境中查看我的应用程序时,它会提示另一个错误。所以现在我有了pgAdmin III和Rails

Now rails server command works fine, and it prompts a different error when I try to look at my app on local environment. So right now I have pgAdmin III and Rails

PG::Error

fe_sendauth: no password supplied

我试图遵循 ,但是我找不到 pg_hba.conf。我猜答案是基于不同的操作系统的。

I tried to follow this, but I couldn't find "pg_hba.conf." I guess the answer was based on a different OS.

现在,捆绑器不能正常工作,给我错误...

And now again, the bundler is not working, giving me errors...

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

Questions: 1) Was I right to install postgreSQL with the one-click installer? Because this caused my ROR to "crash" somehow, and I had to reinstall rails altogether. 2) I think I am going to delete everything related to postgreSQL, reinstall Rails, and start everything from beginning. What are the steps that I have to take? All the references I've looked at do not seem to fit Windows environment.

在我的gemfile文件中,我有

In my gemfile, I have

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 `<main>'

运行捆绑安装时:

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比我想象的要花费更多的时间和精力。对于这个问题,我将不胜感激。

I thought deploying wasn't going to be this hard, but moving from SQLite3 to PostgreSQL is taking more time and effort than I thought it would. I would really appreciate some help on this problem.

---------------------- -------------------------------------------------- ------------------------------------------------

更新:重新安装所有内容后,我将重新进行设置。

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

I checked that my SQLite3 version app worked fine. So I moved onto setting up postgreSQL. I got the following error when I first set up my postgreSQL. By setting up, I mean editing config/database.yml and installing the gem 'pg' and removing the gem 'sqlite3.' When I tried to connect to localhost:3000, I got the following error:

ActiveRecord::ConnectionNotEstablished

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

After some research, I found that there could be more steps to setting the db. So I ran the bundle command,

bundle exec rake db:setup

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

But then in the console, I got the following error when I ran 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 `<top (required)>'
Tasks: TOP => db:schema:load => environment

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

When I tried to connect to localhost:3000, I got the above error again, instead of ActiveRecord::ConnectionNotEstablished.

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

推荐答案

如果遇到错误:

PG::Error

fe_sendauth: no password supplied

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

You have good news, your app can work with PostgreSQL database now. (But you need to configure some thing)

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

After installing PostgreSQL, you can create new rails app using PostgreSQL by command:

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:

您会看到,三个数据库具有用户名密码字段,这是Postgresql中的帐户用户, database.yaml 文件中的三个数据库该用户造成的不适。因此,您需要为其提供用户名密码。默认情况下,安装Postgresql后,它将创建一个用户名为 postgresql 的用户,密码为 postgresql 。可以使用它。

You see that, three database has username and password field, this is account user in Postgresql, three database in database.yaml file will created by this user. So you need to provide username and password for it. Default after install Postgresql, it created a user with username is postgresql and password is postgresql. You can use it.

如果要使用其他用户,只需打开 pgAdmin III 并通过以下方式创建新用户右键单击登录角色,然后选择新登录角色以创建具有密码的新用户。然后将用户名和密码放入 database.yaml 文件。

If you want to use other user, just open pgAdmin III and create new user by right click on Login Roles and choose New login role to create new user with password. Then put that username and password to database.yaml file.

之后,您现在所需要的就是找到并打开 pg_hba.conf 文件,对应用程序进行一些配置即可与PostgreSQL一起使用。我已经很长时间没有使用Windows了,所以我不确定它在哪里,但是您可以在安装PostgreSQL的文件夹中找到。例如,如果您安装在 E:\ 分区上,也许可以在以下位置找到它:

After that, all you need now, is find and open pg_hba.conf file to make some configure for app can work with PostgreSQL. I'm not using Windows for a long time, so I'm not sure where it is, but you can find in folder you installed PostgreSQL. Example, if you install on E:\ partition, maybe you can find it in:

E:\PostgreSQL\version\data

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

After you found it, open and find a line:

# "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数据库。要为应用创建数据库,请运行 rake db:create rake db:create:all 。现在您的应用程序现在可以使用PostgreSQL数据库了,很高兴:)。

Then restart your Postgresql database. To create database for app, run rake db:create or rake db:create:all. Now your app can using PostgreSQL database now, so happy :).

这篇关于Rails:部署到Heroku,存在许多问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆