以下应用程序可以正常使用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
will_paginate
并且无法移除页面Book.scoped.paginate
删除expose(books)
,它可以正常工作,但我不知道如何在没有范围的情况下进行分页。prepared_statement: false
中尝试了database.yml
,并得出结论认为它与此错误无关。问题的根源在哪里?我怎样才能让它发挥作用?
答案 0 :(得分:1)
使用Kaminari
,错误不再存在,我得到了我想要的功能。
深入了解pg
或will_paginate
的内部工作可能会找到问题的原因。