Rails:自动加载库不起作用 [英] Rails: Autoloading lib not working

查看:89
本文介绍了Rails:自动加载库不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的自动装带器无法正常工作,我遵循了一些教程,这是我的config \ application.rb文件的样子

For some reason my autoloader isn't working, i followed some tutorials, here is what my config\application.rb file looks like

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

I am getting this error: uninitialized constant ActionView::CompiledTemplates::PaginationListLinkRenderer

这是我的lib \ paginationlistlinkrenderer.rb代码

Here is my lib\paginationlistlinkrenderer.rb code

class PaginationListLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer

    protected
    ...
    ...

end

这是我的index.html.erb

Here is my index.html.erb

<div id="img_content">
    <%= render @posts%>
</div>

<%= will_paginate(@posts, :renderer => PaginationListLinkRenderer) %>
<%= link_to "New Quote", new_post_path %>

我只需要获取此文件以进行预加载,以便我的控制器识别它.有什么想法吗?

I just need to get this file to pre-load so my controller will recognize it. Any ideas?

推荐答案

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

In your config/initializers folder make a file called pagination.rb and include the following. Restart and it should work.

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分页文件更改为...

Change you Lib pagination File to...

pagination_list_link_renderer.rb

确保您具有最新版本的Will_Pagination.版本3 Pre

Make sure you have the latest version of Will_Pagination. Version 3 Pre

这篇关于Rails:自动加载库不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆