由于某种原因我的自动加载器无法工作,我遵循了一些教程,这是我的 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/initializers 文件夹中创建一个名为 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 预
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)