ActionView::Template::Error (undefined method `get?' for nil:NilClass): #122

Closed
nazarhussain opened this Issue Apr 8, 2011 · 5 comments

Projects

None yet

2 participants

@nazarhussain

Hi i created my own helper and passed the array of objects to it. And from there i want to get the pagination results.

def processed_pagination
     content_tag(:div, will_paginate(@object), :class=>"list-pagination")
end

but it is generating error

 ActionView::Template::Error (undefined method 'get?' for nil:NilClass):

I also tried to include in the class

include ActionView::Helpers::UrlHelper
include Rails.application.routes.url_helpers

but no way, error is still there.

@mislav
Owner
mislav commented Aug 9, 2011

Where did you define this helper? Which version of Rails?

@nazarhussain

I created it in ApplicationHelper

@mislav
Owner
mislav commented Aug 10, 2011

I'm guessing this is Rails 3.0.9.

Where are you calling processed_pagination from? Regular view template, or somewhere else?

Your error is because the request object is missing, which means that you might be rendering pagination links outside of the context of a request/response cycle.

@nazarhussain

Yes, i was calling in in class, which was in lib. Actually i was writing a plugin to show list of objects based on some selection. Then how to solve this issue?

@mislav
Owner
mislav commented Aug 10, 2011

OK I did a few tweaks in b385f38 and wrote tests to confirm it works. Switch your Gemfile to use will_paginate from git master and you can try it out:

class MyClass
  include ActionDispatch::Routing::UrlFor
  include Rails.application.routes.url_helpers
  include WillPaginate::ActionView

  default_url_options[:controller] = 'home'
  # if you want full URLs:
  default_url_options[:host] = 'example.com'
  # if you want only paths:
  default_url_options[:only_path] = true
end

MyClass.new.will_paginate(collection)
@mislav mislav closed this Aug 10, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment