以下应用程序与 sqlite 一起正常工作。
图书模型
class Book < ActiveRecord::Base
attr_accessible :month, :pages, :title, :year, :author_attributes, :publisher_attributes
belongs_to :author
belongs_to :publisher
accepts_nested_attributes_for :author
accepts_nested_attributes_for :publisher
end
图书控制器
class BooksController < ApplicationController
respond_to(:html)
expose(:books, :ancestor => [:author, :publisher]) { Book.scoped.paginate(:page => params[:page], :per_page=>params[:per_page])}
expose(:book)
# other functions here
end
使用postgresql,当我尝试访问时出现以下错误http://localhost:3000/books/1
ActiveRecord::StatementInvalid in Books#show
Showing /Users/tunwinnaing/Projects/rails_projects/books/app/views/books/show.html.haml where line #1 raised:
PG::UndefinedParameter: ERROR: there is no parameter $1
LINE 1: SELECT COUNT(*) FROM "books" WHERE "books"."id" = $1
^
: SELECT COUNT(*) FROM "books" WHERE "books"."id" = $1
Extracted source (around line #1):
1: - provide( :title, "#{book.title} | " )
2: %h1= book.title
3: %hr
4: .row
背景资料
- 红宝石 1.9.3
- 导轨 3.2.13
- 体面曝光 2.2.0
- will_paginate 3.0.3
- 第 0.16.0 页
- postgresql 9.x(使用 postgresapp)
尝试了以下
- 是什么导致 PGError: ERROR: there is no parameter $1 in my Rails app - 我需要
will_paginate
但无法删除页面 - 如果我删除了
Book.scoped.paginate
fromexpose(books)
,它可以工作,但我不知道如何在没有范围的情况下进行分页。 - 我尝试
prepared_statement: false
并database.yml
得出结论,它与此错误无关。
这里问题的根源是什么?我怎样才能让它发挥作用?