Rails:自动加载lib无法正常工作

时间:2011-05-25 09:35:32

标签: ruby-on-rails config loader

由于某种原因,我的自动加载器无法正常工作,我按照了一些教程,这是我的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 %>

我只需要预先加载此文件,以便我的控制器识别它。有什么想法吗?

2 个答案:

答案 0 :(得分:5)

在config / initializers文件夹中创建一个名为pagination.rb的文件,并包含以下内容。重启,它应该工作。

module WillPaginate::ViewHelpers
    # default options that can be overridden on the global level
    @@pagination_options = {
      :class        => 'pagination',
      :previous_label   => '&laquo; Previous',
      :next_label   => 'Next &raquo;',
      :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 Pre

答案 1 :(得分:0)

只需改变:

lib \ paginationlistlinkrenderer.rb 代码

class PaginationListLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer

    protected
    ...
    ...

end

class PaginationListLinkRenderer < WillPaginate::ActionView::LinkRenderer

    protected
    ...
    ...

end