问题与rails服务器 [英] Problems with rails server

查看:98
本文介绍了问题与rails服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用rails和heroku上的ruby。我正在关注herokus网站上的入门指南,但遇到了问题。我已经登录到heroku,创建了一个应用程序,如 rails new myapp --database = postgresql 然后创建一个控制器 rails generate controller welcome index code>在 app / views / welcome / index.html.erb中我刚创建了一个名为hello world的头文件。当我启动本地服务器并转到它时,我得到无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受Unix域套接字上的连接/tmp/.s.PGSQL .5432?和输出在终端中列出的下面我跟着另一个教程只是为了设置没有heroku的rails,并创建了这样的应用程序 rails new blog ,然后像在heroku教程中创建控制器一样,一切正常,所以我假设问题出在 rails new myapp --database = postgresql How我可以解决这个问题吗?

  PG :: ConnectionBad(无法连接到服务器:没有这样的文件或目录
Is服务器在本地运行并接受Unix域套接字上的
连接/tmp/.s.PGSQL.5432?
):
activerecord(4.0.2)lib / active_record / connection_adapters / postgresql_adapter .rb:831:在`initialize'
activerecord(4.0.2)lib / active_record / connection_adapters / po在`new'
activerecord(4.0.2)lib / active_record / connection_adapters / postgresql_adapter.rb:831:in`connect'
activerecord(4.0.2)lib / active_record /在'initialize'
activerecord(4.0.2)lib / active_record / connection_adapters / postgresql_adapter.rb:41:in`new'
activerecord(4.0.2)lib /在``new_connection'
activerecord(4.0。)中激活记录/连接适配器/ postgresql_adapter.rb:41:在`postgresql_connection'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:440: 2)lib / active_record / connection_adapters / abstract / connection_pool.rb:450:in`checkout_new_connection'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:421:在'acquire_connection'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:356:在`block in checkout'
/Users/mattmoss/.rbenv/版本/ 2.1.0 / lib / ruby​​ / 2.1.0 / monitor.rb:211:在`mon_synchronize'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:355: checkout'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:265:在`block in connection'
/Users/mattmoss/.rbenv/versions/2.1.0/ lib / ruby​​ / 2.1.0 / monitor.rb:211:在`mon_synchronize'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:264:in`connection'
activerecord(4.0.2)lib / active_record / connection_adapters / abstract / connection_pool.rb:546:在'retrieve_connection'
activerecord(4.0.2)lib / active_record / connection_handling.rb:79:在'retrieve_connection'
activerecord(4.0.2)lib / active_record / connection_handling.rb:53:在`connection'
activerecord(4.0.2)lib / active_record / query_cache.rb:51:在'restore_query_cache_settings'
activerecord(4.0.2)lib / active_record / query_cache.rb:43:i在调用'
activerecord(4.0.2)lib / active_record / query_cache.rb:32:在'call' rb:626:在'call'中
activerecord(4.0.2)lib / active_record / migration.rb:369:在'call'中
actionpack(4.0.2)lib / action_dispatch / middleware / callbacks。 rb:29:在`block in call'中
activesupport(4.0.2)lib / active_support / callbacks.rb:373:在_run__4242016335734095215__call__callbacks'
activesupport(4.0.2)lib / active_support / callbacks。 rb:80:在`run_callbacks'
actionpack(4.0.2)lib / action_dispatch / middleware / callbacks.rb:27:in`call'
actionpack(4.0.2)lib / action_dispatch / middleware / reloader.rb:64:in`call'
actionpack(4.0.2)lib / action_dispatch / middleware / remote_ip.rb:76:在`call'中
actionpack(4.0.2)lib / action_dispatch /中间件/ debug_exceptions.rb:17:在`call'中
actionpack(4.0.2)lib / action_dispatch / middleware / show_exceptions.rb:30 :在`call'
railties(4.0.2)lib / rails / rack / logger.rb:38:在`call_app'
railties(4.0.2)lib / rails / rack / logger.rb :20:在`block in call'中
activesupport(4.0.2)lib / active_support / tagged_logging.rb:67:在`block in tagged'
activesupport(4.0.2)lib / active_support / tagged_logging .rb:25:在`tagged'
activesupport(4.0.2)lib / active_support / tagged_logging.rb:67:在'tagged'
railties(4.0.2)lib / rails / rack / logger .rb:20:在`call'
actionpack(4.0.2)lib / action_dispatch / middleware / request_id.rb:21:在`call'
rack(1.5.2)lib / rack / methodoverride .rb:21:在`call'中
rack(1.5.2)lib / rack / runtime.rb:17:在`call'中
activesupport(4.0.2)lib / active_support / cache / strategy /local_cache.rb:83:in`call'
rack(1.5.2)lib / rack / lock.rb:17:在`call'中
actionpack(4.0.2)lib / action_dispatch / middleware /static.rb:64:in`call'
rack(1.5.2)lib / rack / sendfile.rb:112:在`call'中
railties(4.0.2)lib / rails / eng ine.rb:511:在`call'
railties(4.0.2)lib / rails / application.rb:97:在`call'
rack(1.5.2)lib / rack / lock。 rb:17:在`call'
rack(1.5.2)lib / rack / content_length.rb:14:在`call'
rack(1.5.2)lib / rack / handler / webrick中。 rb:60:在`service'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in`service'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in`run'
/Users/mattmoss/.rbenv/versions/2.1。 0 / lib / ruby​​ / 2.1.0 / webrick / server.rb:295:在`block in start_thread'


渲染/Users/mattmoss/.rbenv/versions/2.1.0 /lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_source.erb(0.5ms)
呈现/Users/mattmoss/.rbenv/versions /2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb(1.0ms)
渲染/用户/ mattmoss / .rbenv /版本/ 2.1.0 / lib中/红宝石/宝石/ 2.1.0 /宝石/诉权(1.0ms)
渲染/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1。 0 / gems / actionpack-4.0.2 / lib / action_dispatch / middleware / templates / rescues / diagnostics.erb in rescue / layout(18.2ms)

这是我的database.yml

 #PostgreSQL。支持版本8.2及以上。 

#安装pg驱动程序:
#gem install pg
#在OS X上使用Homebrew:
#gem install pg - --with-pg- config = / usr / local / bin / pg_config
#在OS X上使用MacPorts:
#gem install pg - --with-pg-config = / opt / local / lib / postgresql84 / bin / pg_config
#在Windows上:
#gem install pg
#选择win32版本。
#安装PostgreSQL并将其/ bin目录放在您的路径中。

#配置使用Gemfile
#gem'pg'

开发:
适配器:postgresql
编码:unicode
数据库:myapp_development
池:5
密码:

#在TCP套接字上连接。默认情况下省略,因为客户端使用不需要配置的
#域套接字。 Windows没有
#域套接字,所以取消注释这些行。
#host:localhost

#服务器侦听的TCP端口。默认为5432.
#如果您的服务器运行在不同的端口号上,请相应地更改。
#port:5432

#架构搜索路径。服务器默认为$ user,public
#schema_search_path:myapp,sharedapp,public
$ b $最小日志级别,按升序排列:
#debug5,debug4,debug3,debug2, debug1,
#日志,通知,警告,错误,致命和恐慌
#默认为警告。
#min_messages:notice

#警告:当您运行rake时,定义为test的数据库将被删除,并且从开发数据库重新生成
#。
#不要将此db设置为与开发或生产相同。
测试:
适配器:postgresql
编码:unicode
数据库:myapp_test
池:5
密码:

生产:
适配器:postgresql
编码:unicode
数据库:myapp_production
池:5
密码:

开发:
主机: localhost

test:
host:localhost


解决方案

在你的 config / database.yml 中,尝试添加

  host:localhost 

在您的每个开发和测试环境中,或者更具体地查看您的现有 config / database.yml 如上所示:

 开发:
适配器:postgresql
编码:unicode
数据库:myapp_development
池:5
密码:
主机:localhost

测试:
适配器:postgresql
编码:unicode
数据库:myapp_test
池:5
passwo rd:
host:localhost

希望这可以帮助您

I am just getting started with ruby on rails and heroku. I am following the getting started guid on herokus website but have ran into a problem. I have logged into heroku, created an app as such rails new myapp --database=postgresql and then created a controller rails generate controller welcome index in the app/views/welcome/index.html.erb I just created a header saying hello world. When I start a local server and go to it, I get could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? and the output listed bellow in the terminal I followed another tutorial just for setting up rails without heroku and created the app like this rails new blog and then did the same as created a controller like in the heroku tutorial and everything worked fine, so I assume the problem is with rails new myapp --database=postgresql How would I fix this?

PG::ConnectionBad (could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
):
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
  /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
  /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
  activerecord (4.0.2) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
  activerecord (4.0.2) lib/active_record/connection_handling.rb:53:in `connection'
  activerecord (4.0.2) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
  activerecord (4.0.2) lib/active_record/query_cache.rb:43:in `rescue in call'
  activerecord (4.0.2) lib/active_record/query_cache.rb:32:in `call'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4242016335734095215__call__callbacks'
  activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.2) lib/rails/engine.rb:511:in `call'
  railties (4.0.2) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'


  Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
  Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
  Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (18.2ms)

Here is my database.yml

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # Defaults to warning.
  #min_messages: notice

# 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: unicode
  database: myapp_test
  pool: 5
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: myapp_production
  pool: 5
  password:

development:
  host: localhost

test:
  host: localhost

解决方案

In your config/database.yml, try adding

host: localhost

in each of your development and testing environment or more specifically looking at your existing config/database.yml shown above:

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  password:
  host: localhost

test:
  adapter: postgresql
  encoding: unicode
  database: myapp_test
  pool: 5
  password:
  host: localhost

Hope this helps

这篇关于问题与rails服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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