Tag: postgresql

ActiveRecord查询,按关联顺序,has_many的最后一个

我试图通过最近创建的关联的recored(通信)的created_at列列出所有用户 。 到目前为止我所拥有的: User.includes(:communications).order( ‘communications.created_at IS NULL, communications.created_at asc’ ) 事实上, desc工作正如我所料。 问题是当订单被撤销时我尝试订购asc 。 它似乎是因为用户可以有很多通信 ,查询按照创建的第一个通信而不是最新通信的顺序返回用户列表。 如何修改查询以定位asc和desc顺序中最近创建的关联记录? 谢谢你的时间。

Heroku错误:ActionView :: Template :: Error(未定义的方法`validation码’用于#)

一切都在我当地的环境中正常运作。 当我尝试部署到heroku并最初查看我的网站时,它给了我以下错误:“我们很抱歉,但出了点问题。如果您是应用程序所有者,请查看日志以获取更多信息。” 当我检查我的“heroku日志”时,我发现此错误消息: ActionView :: Template :: Error(未定义的方法`captcha’用于-Message:0x007fc9df016930-) HTML表单视图/ pages / index.html.erb “message_name_input message_input_default”, :placeholder => ” First Name” %> “message_name_input message_input_default”, :placeholder => ” Last Name” %> true, :class => “message_email_input message_input_default”, :placeholder => ” * Email” %> true, :class => “message_user-message_input”, :placeholder => ” * Write a message” %> true, :class => “message_input_default”, […]

使用rvm在Mac OS Lion上安装pg gem

212-178-13-214:~ igorfedoronchuk$ gem install pg Building native extensions. This could take a while… /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777 ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb checking for pg_config… yes Using config values from /usr/bin/pg_config checking for libpq-fe.h… *** extconf.rb failed *** Could not […]

PG ::错误:错误:关系schema_migrations的权限被拒绝

不知道为什么我遇到这个错误。 我正确设置了postgresql,只是运行了一个迁移,然后rake db:migrate,我得到了标题错误。 这是我的: database.yml的 development: adapter: postgresql encoding: unicode database: my_blog_development pool: 5 username: my_blog password: test: adapter: postgresql encoding: unicode database: my_blog_test pool: 5 username: my_blog password: production: adapter: postgresql encoding: unicode database: my_blog_production pool: 5 username: my_blog password: 完整错误: [my_blog]$rake db:migrate rake aborted! PG::Error: ERROR: permission denied for relation schema_migrations : SELECT […]

Heroku – 如何将数据从数据库提取到本地数据库?

我试图在Heroku上获取数据库,并从那里获取数据以保存到我的本地数据库中。 当我尝试 heroku db:pull 并确认应用程序的名称,我得到: ! db:push and db:pull have been removed and replaced with pg:push and pg:pull. ! For more information, please see: ! devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull 好的,所以: pg:pull 收益: -bash: pg:pull: command not found heroku pg:pull 回报 ! `pg:pull` is not a heroku command. ! Perhaps you meant `db:pull` or `pg:psql`. ! See `heroku help` […]

Active_support / dependencies.rb:247`require’:无法加载此类文件 – 2.1 / pg_ext(LoadError)

我在Windows机器上使用Ruby 2.1.5,Rails 4.1.6和PostgreSQL 9.3.5。 当我尝试bundle exec rails server ,我最终得到以下错误: DL is deprecated, please use Fiddle c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require’: cannot load such file — 2.1/pg_ext (LoadError) from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in re…re’ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependancy’ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require’ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/pg-0.17.1-x86-mingw32/lib/pg.rb:10:in `rescue in ‘ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/pg-0.17.1-x86-mingw32/lib/pg.rb:3:in `’ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.rb:76:in `require’ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.rb:76:in `block (2 levels) in require’ from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.rb:72:in […]

Rails通过现有数据库进行迁移

我正在创建一个新的Rails 3.1应用程序。 我希望这个新的应用程序重用现有的数据库(由之前的rails 2应用程序创建)。 我创建了定义模型的新应用程序,它重用了数据库中的一些现有数据。 在开发和测试阶段,一切正常,因为它在一个干净的工作表数据库上运行,但在尝试部署到生产时,我得到的消息如下: PGError: ERROR: column “email” of relation “users” already exists *** [err :: localhost] : ALTER TABLE “users” ADD COLUMN “email” character varying(255) DEFAULT ” NOT NULL 但是我在我的迁移中认为是这样的 class DeviseCreateUsers false t.recoverable t.rememberable t.trackable t.timestamps end end 如何使db:migrate忽略已存在的内容并仅更改新内容和/或新类型? 我在stackoverflow上看到了类似的问题,但没有人回答这个问题。 谢谢你的回答。

Rails PostgreSQL数字字段溢出ERROR

我的架构上有一个十进制字段的价格,每次我尝试插入价格时,pg都带有此错误。 谁能给我任何光? 谢谢 组态 t.decimal “price”, :precision => 2, :scale => 2 错误 PG::Error: ERROR: numeric field overflow DETAIL: A field with precision 2, scale 2 must round to an absolute value less than 1. : INSERT INTO “items” (“category_id”, “name”, “price”, “updated_at”) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, […]

Rails:如何连接到旧的PostgreSQL(你的PostgreSQL版本(70417)太旧了,请升级!)

尝试建立与远程PostgreSQL的连接,我收到错误: RuntimeError:您的PostgreSQL版本(70417)太旧了,请升级! 来自/Users/panayi/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems /activerecord-3.2.11/lib/active_record/connection_adapters /postgresql_adapter.rb:331:in`initialize “ 我无法访问PostgreSQL,因此无法升级。 我试过使用旧的pg gem: # Gemfile gem ‘pg’, ‘~> 0.9.0’ 但后来我得到: LoadError:请安装postgresql适配器: gem install activerecord-postgresql-adapter (无法激活pg(〜> 0.11),已激活pg-0.9.0。确保所有依赖项都已添加到Gemfile中。) 我被卡住了。

Rails:如何在activerecord中查询模型的时间范围,而不是日期

我有一个带time属性的模型。 它是用户想要收到电子邮件的配置,即美国东部标准时间下午5点。 它以21:00:00存储在数据库中。 我想按范围查询。 例如,我希望每个用户的提醒时间在20:55:00到21:05:05之间。 Rails似乎奇怪地处理时间属性,因为它想要将它显示为完整的DateTime,因此数据库有21:00:00但是当加载到rails时,它显示为2000-01-01 17:00:00。 我的代码现在看起来像: scope :receives_report_reminder_at, -> (time) do start = (time – 5.minutes).strftime(‘%T’) ending = (time + 5.minutes).strftime(‘%T’) where(notification_report_reminder_time: start…ending) end 这适用于我的测试用例,但是当我在测试之外尝试时它不起作用。 思考? 有没有一种正确的方法来处理场景,或者我错了吗?