由于某些原因,我的自动加载器无法工作,我遵循了一些教程,以下是我的config\application.rb文件看起来像
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Quotes
class Application < Rails::Application
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)
我收到以下错误:未初始化的常量ActionView::CompiledTemplates::PaginationListLinkRenderer
这是我的lib\paginationlistlinkrenderer.rb代码
class PaginationListLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer
protected
...
...
end
这是我的index.html.erb
<div id="img_content">
<%= render @posts%>
</div>
<%= will_paginate(@posts, :renderer => PaginationListLinkRenderer) %>
<%= link_to "New Quote", new_post_path %>
我只需要预先加载这个文件,这样我的控制器就能识别它。有什么想法吗?
在config/ininitializers文件夹中创建一个名为pagination.rb的文件,并包含以下内容。重新启动,它应该可以工作。
module WillPaginate::ViewHelpers
# default options that can be overridden on the global level
@@pagination_options = {
:class => 'pagination',
:previous_label => '« Previous',
:next_label => 'Next »',
:inner_window => 2, # links around the current page
:outer_window => -1, # links around beginning and end
:limit => 5,
:separator => ' ', # single space is friendly to spiders and non-graphic browsers
:param_name => :page,
:params => nil,
:gap => "...",
:renderer => '::PaginationListLinkRenderer',
:page_links => true,
:container => true
}
mattr_reader :pagination_options
end
将Lib分页文件更改为…
pagination_list_link_renderer.rb
请确保您拥有最新版本的Will_Pagination。版本3 前
只需更改:
lib\paginationlistlinkrenderer.rb代码
class PaginationListLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer
protected
...
...
end
至
class PaginationListLinkRenderer < WillPaginate::ActionView::LinkRenderer
protected
...
...
end