我每次运行Rails应用程序(It cannot connect to my local Postgresql)时都会出现此错误

/Users/leonardo/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.11/lib/
active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': 
could not connect to server: No such file or directory (PG::Error)
   Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

我用Postgres.app表示它运行正常.

如果我跑

$ psql

我可以正确登录Postgresql控制台.

$ which psql
 /Applications/Postgres.app/Contents/MacOS/bin/psql

Gemfile

source 'https://rubygems.org'
ruby "1.9.3"

gem 'rails', '3.2.11'
gem "pg"

database.yml

development:
  adapter: postgresql
  encoding: unicode
  username: leonardo
  password: 
  database: zapping
  port: 5432  

Postgresql(控制台)

$ psql
leonardo=# \l

在此处输入图像描述

推荐答案

try 将host: localhost添加到数据库中.yml.(基于:https://stackoverflow.com/a/10793186/919641)

Ruby-on-rails相关问答推荐

Rails 7.0.4 和 link_to 的数据确认不起作用

显示每个 rspec 示例的运行时

在 Rails 中找不到关联问题

Rails 4 Form: has_many through: checkboxes

在命名空间内设计

从子类中的重载方法调用基类方法

在 Ruby on Rails 上,我们如何在控制器中打印调试信息?

是否有与 PHP 的 isset() 等效的 Rails?

如何获取包含表的列名的数组

我应该将全局共享部分模板放在哪个文件夹中?

Rails Rake 任务 - 访问模型类

在 rails 3 中批量插入

如何打印出范围之间的随机数?

Ruby 根据属性在数组中查找并返回对象

如何在 Rails 应用程序中测试 ElasticSearch (Rspec)

在 Rails 中,在特定时区创建特定时间(不是现在)的最佳方式是什么?

ActiveRecord 中多列的索引

即使X-Frame-Options为ALLOWALL,也无法在 iframe 中显示我的 rails 4 应用程序

您将如何解析 Ruby 中的 url 以获取主域?

按照给定 ID 数组的顺序按 ID 查找模型记录