Tag: postgresql

保存失败后Rails没有回滚事务()

我有这个域模型:用户有一组项目,项目的状态可能无法通过validation。 validation工作正常,我甚至看到当我使用save!时调用exceptionsave! 。 在我的控制器中,我有这个: @user.items() < {}, :status => :ok else render :json => {:status => :error, :errors => item.errors}, :status => :bad_request end 第一个POST成功,第二个POST失败,但是当我点击索引时,我仍然看到两个对象,好像第二个事务从未回滚过。 到底是怎么回事? 我的测试是这样的: post :create post :create get :index ActiveSupport::JSON.decode(response.body).length.should == 1 编辑:即使在运行服务器时,也不会回滚事务(sqlite3)。

简单的Rails应用程序:错误无法访问整数

我正在尝试构建一个简单的Rails应用程序。 Rails v3.2.22.5(这是一项要求)。 我用PostgreSQL运行它。 当我启动服务器但是当我尝试从数据库中读取一个简单的post时,我收到以下错误。 无法访问Integer 跟踪引导我进入下面的show方法。 更具体到第二行。 我是Rails的新手,对于如何解决这个问题一无所知。 搜索网络已经没有成功。 任何想法都会受到欢迎。 def show @post = Post.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @post } end end 完整追踪: arel (3.0.3) lib/arel/visitors/visitor.rb:25:in `rescue in visit’ arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit’ arel (3.0.3) lib/arel/visitors/to_sql.rb:241:in `visit_Arel_Nodes_Limit’ arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit’ arel (3.0.3) lib/arel/visitors/to_sql.rb:123:in `visit_Arel_Nodes_SelectStatement’ arel (3.0.3) […]

heroku db:拉不工作

heroku db:pull postgresql://root:@localhost/db_name 此命令显示此消息后 /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/abstract_response.rb:50:警告:未来版本的parenthesize参数Loaded Taps v0.3.13警告:数据输入数据库’postgresql:// root:@ localhost / db_name’将被覆盖,无法恢复。 你确定要继续吗? (Y / N)? y无法连接数据库:Sequel :: AdapterNotFound – > LoadError:没有要加载的文件 – 续集/ adapters / postgresql 如何使用db:pull

从ActiveRecord原始SQL获取类型化结果

在续集中,我可以这样做: irb(main):003:0> DB[“select false”].get => false 返回false布尔值。 我希望能够在ActiveRecord中做类似的事情: irb(main):007:0> ActiveRecord::Base.connection.select_value “select false” => “f” 如您所见,它返回字符串”f” 。 有没有办法用ActiveRecord获取一个假布尔值? (同样,我可能正在调用一个返回timestamptz,数组等的函数 – 我希望返回的值具有正确的类型) 我的用例:我正在调用数据库函数,想要取回一个键入的结果而不是字符串。

如何使“喜欢条款”不区分大小写

嗨我在Ruby On Rails中使用LIKE子句,当我尝试通过键入“more”来搜索记录时它不会返回任何内容,但是当我使用“More”时 ,它会返回包含More keyword的记录,所以它似乎表现为区分大小写 , 现在我的问题是我们可以将它设为Case-Insensitive ,如果是,那么请告诉我。 这是我目前使用的查询: Job.where(‘title LIKE ? OR duration LIKE ?’, “%#{params[:search]}%”, “%#{params[:search]}%”) 谢谢。

为PostgreSQL 8.3安装PL / Ruby

这是为了使用嵌入式ruby代码开发postgres函数,但我无法构建它。 根据http://www.robbyonrails.com/articles/2005/08/22/installing-untrusted-pl-ruby-for-postgresql的建议 我正在尝试从ftp://moulon.inra.fr/pub/ruby/上提供的最新版本(plruby-0.5.3.tar.gz)构建所需的plruby.so。 我已经整理了我的本地postgres设置的位置,并将调用调整为: ruby extconf.rb –with-pgsql-include=/usr/postgresql-8.3.4/include/server –enable-shared –disable-conversion –with-pgsql-version=83 我已经尝试了很多变种,但它似乎无法成功制作’conftest.c’文件 它说: checking for catalog/pg_proc.h… yes *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. 以下是我在mkmf.log中的最终结果 have_header: checking for catalog/pg_proc.h… ——————– yes “gcc […]

PG错误无法连接到服务器:连接被拒绝服务器是否在端口5432上运行?

我最近更新了我的机器(运行Mountain Lion的MacBook Pro),从那时起,每当我设置一个rails项目时,我的机器就会崩溃,无法连接到PG。 目前,这是我尝试去localhost时遇到的错误; PG :: ERROR无法连接到服务器:连接被拒绝服务器是否在主机“localhost”上运行 (:1)并接受端口5432上的TCP / IP连接? 无法连接到服务器:连接 拒绝服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口5432上的TCP / IP连接? 无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(fe80 :: 1)上运行并接受端口5432上的TCP / IP连接? 这是一份清单,以及我尝试的事项清单; PostgreSQL版本是9.3.4 我通过HomeBrew安装它 我在我的database.yml文件中有host: localhost Rails版本4.1.1,ruby 2.0.0p247(2013-06-27修订版41674)[x86_64-darwin12.5.0] 然后brew install postgresql brew uninstall postgresql然后brew install postgresql 试图访问我的postgres.conf文件,但不允许通过PGAdmin和命令行 然后locate pg_hba.conf并终端出来了; WARNING: The locate database (/var/db/locate.database) does not exist. 我也试过使用rails 4.0,但我仍然遇到了问题 在我更新计算机之前,我仍然可以在我的机器上处理启动/完成的其他项目。 当我从终端运行psql ,我得到psql: could not connect to server: […]

升级后的pg_config,ruby pg,postgresql 9.0问题,centos 5

在postgresql 8.1升级到9.0之后,我发现了库依赖的问题。 Postgresql工作正常(连接,查询)。 yum list postgresql* Installed Packages postgresql.i386 9.0.0-1PGDG.el5 installed postgresql-debuginfo.i386 9.0.0-1PGDG.el5 installed postgresql-devel.i386 9.0.0-1PGDG.el5 installed postgresql-libs.i386 9.0.0-1PGDG.el5 installed postgresql-odbcng.i386 0.90.101-2.el5 installed postgresql-plruby.i386 0.5.1-5.el5 installed postgresql-server.i386 9.0.0-1PGDG.el5 install 但当我试图为ruby安装’pg’时,我收到了 gem install pg Building native extensions. This could take a while… ERROR: Error installing pg: ERROR: Failed to build gem native extension. /usr/local/bin/ruby extconf.rb checking […]

Rails迁移更改列以使用Postgres数组

我试图更改我的数据库中的列,以便它可以使用Postgres数组数据类型。 目前,表列的类型为string。 我使用以下迁移来转换它: def change change_column :table, :dummy_column, :text, array: true, default: [] end 但是我收到以下错误: bundle exec rake db:migrate rake aborted! An error has occurred, this and all later migrations canceled: PG::Error: ERROR: column “dummy_column” cannot be cast automatically to type character varying[] HINT: Specify a USING expression to perform the conversion. : ALTER TABLE […]

Rails无法登录postgresql – PG ::错误 – 密码 – 正确的信息

这就是我的database.yml文件的外观(显然还有相关的测试和生产条目) development: adapter: postgresql encoding: unicode database: dbname_dev pool: 5 username: username password: tehpass 在终端中,我可以成功运行以下命令并登录数据库: psql -U username dbname_dev 但是在创建了这个新的rails项目并运行之后 rails g controller ComingSoon index 当我转到localhost:3000 / coming_soon时,我收到以下消息(尽管双重和三重检查登录凭据) fe_sendauth: no password supplied 任何想法为什么我可以通过“psql”登录到这些数据库,但Rails不能?