开发者

Rails: Autoloading lib not working

开发者 https://www.devze.com 2023-03-08 01:39 出处:网络
For some reason my autoloader isn\'t working, i followed some tutorials, here is what my config\\application.rb file looks like

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)

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

Here is my lib\paginationlistlinkrenderer.rb code

class PaginationListLinkRenderer < WillPaginate::ViewHelper开发者_开发问答s::LinkRenderer

    protected
    ...
    ...

end

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?


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

Change you Lib pagination File to...

pagination_list_link_renderer.rb

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


Just change:

lib\paginationlistlinkrenderer.rb code

class PaginationListLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer

    protected
    ...
    ...

end

To

class PaginationListLinkRenderer < WillPaginate::ActionView::LinkRenderer

    protected
    ...
    ...

end
0

精彩评论

暂无评论...
验证码 换一张
取 消