Error: uninitialized constant WillPaginate::ActionView (NameError) when using generator with Pundit

StackOverflow https://stackoverflow.com/questions/22926013

Question

My app was using CanCan but now I'd like to switch to Pundit. I added Pundit to the Gemfile, deleted CanCan, ran bundle and then, when trying to run the generator (rails g pundit:install), I got the error:

...config/initializers/bootstrap_link_renderer.rb:1:in `<top (required)>': uninitialized constant WillPaginate::ActionView (NameError)

Here is my application_controller.rb file:

class ApplicationController < ActionController::Base
  include Pundit

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_filter :configure_permitted_parameters, if: :devise_controller?

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:account_update) << :avatar
  end

  def after_sign_in_path_for(resource)
    topics_path
  end
end

Here is the bootstrap link renderer:

class BootstrapLinkRenderer < WillPaginate::ActionView::LinkRenderer 
  def html_container(html)
    tag(:ul, html, container_attributes)
  end

  def page_number(page)
    tag :li, 
    link(page, page, rel: rel_value(page)), 
    class: ('active' if page == current_page)
  end

  def gap
    tag :li, 
    link(super, '#'), 
    class: 'disabled'
  end  

  def previous_or_next_page(page, text, classname)
    tag :li, link(text, page || '#')
  end

  def previous_page
    num = @collection.current_page > 1 && @collection.current_page - 1
    previous_or_next_page(num, '&laquo;', 'previous_page')
  end

  def next_page
    num = @collection.current_page < total_pages && @collection.current_page + 1
    previous_or_next_page(num, '&raquo;', 'next_page')
  end
end
Was it helpful?

Solution

Try removing the config/initializers/bootstrap_link_renderer.rb for now to see if the problem persists. It's probably unrelated to the CanCan -> Pundit change.

OTHER TIPS

If you wanted to keep the file you could try adding the two following lines to the top

require 'will_paginate/view_helpers/link_renderer'
require 'will_paginate/view_helpers/action_view'

It may be it simply cannot find them automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top