Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wf_filter gives 'Called id for nil,' error #28

Open
anu-vaid opened this issue Jul 19, 2012 · 4 comments
Open

wf_filter gives 'Called id for nil,' error #28

anu-vaid opened this issue Jul 19, 2012 · 4 comments

Comments

@anu-vaid
Copy link

Tried to use will_filter but cannot get it to work.

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Extracted source (around line #2):

1: <div style="margin:0;padding:0;display:inline">
2:   <%= hidden_field_tag(:wf_id, wf_filter.id) %>
  1. I did all steps as outlined in the doc.
  2. Since I am also using will_paginate, to avoid conflict, I added this to config/initializers/kaminari.rb

Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari

if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
def per(value = nil) per_page(value) end
def total_count() count end
end
end
module CollectionMethods
alias_method :num_pages, :total_pages
end
end
end
end

@berk
Copy link
Owner

berk commented Jul 19, 2012

Where are you getting this error? Is it from your code or from will_filter
partials?

wf_filter is not really exposed this way - it is injected into the
collection model that was filtered. For example,
if you did in the controller:

@users = User.filter(:params => params)

then you can access will filter:

@users.wf_filter.id

Can you show me a full example of what you do?

On Thu, Jul 19, 2012 at 10:55 AM, anu-vaid <
reply@reply.github.com

wrote:

Tried to use will_filter but cannot get it to work.

Called id for nil, which would mistakenly be 4 -- if you really wanted

the id of nil, use object_id
Extracted source (around line #2):

1: <div style="margin:0;padding:0;display:inline">
2:   <%= hidden_field_tag(:wf_id, wf_filter.id) %>
  1. I did all steps as outlined in the doc.
  2. Since I am also using will_paginate, to avoid conflict, I added this to
    config/initializers/kaminari.rb

Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari

if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
def per(value = nil) per_page(value) end
def total_count() count end
end
end
module CollectionMethods
alias_method :num_pages, :total_pages
end
end
end
end


Reply to this email directly or view it on GitHub:
#28

@anu-vaid
Copy link
Author

Thanks for the quick response. Here's what I did

  1. In gemfile

gem "will_filter"
gem "kaminari"

  1. bundle install
  2. rails generate "will_filter"
    rake db: migrate
  3. In routes file

MyApp::Application.routes.draw do
mount WillFilter::Engine => "/will_filter

  1. In controller

class UsersController < ApplicationController

def index
@users = User.filter(:params => params)
end

end

  1. In view
    <%= will_filter_tag(@users) %>

I got an undefined method 'per' error. Read some and realized kaminari is conflicting with will_paginate so added

  1. In config/initializers/kaminari.rb

    Kaminari.configure do |config|
    config.page_method_name = :per_page_kaminari

    if defined?(WillPaginate)
    module WillPaginate
    module ActiveRecord
    module RelationMethods
    def per(value = nil) per_page(value) end
    def total_count() count end
    end
    end
    module CollectionMethods
    alias_method :num_pages, :total_pages
    end
    end
    end
    end

and then I get

Called id for nil, which would mistakenly be 4 -- if you really wanted
the id of nil, use object_id
Extracted source (around line #2):

1:


2: <%= hidden_field_tag(:wf_id, wf_filter.id) %>

when I try and go to /companies/1/users


Anupama Vaid
www.parentsquare.com
805.637.8381

On Jul 19, 2012, at 11:25 AM, Michael Berkovich wrote:

Where are you getting this error? Is it from your code or from will_filter
partials?

wf_filter is not really exposed this way - it is injected into the
collection model that was filtered. For example,
if you did in the controller:

@users = User.filter(:params => params)

then you can access will filter:

@users.wf_filter.id

Can you show me a full example of what you do?

On Thu, Jul 19, 2012 at 10:55 AM, anu-vaid <
reply@reply.github.com

wrote:

Tried to use will_filter but cannot get it to work.

Called id for nil, which would mistakenly be 4 -- if you really wanted
the id of nil, use object_id
Extracted source (around line #2):

1:


2: <%= hidden_field_tag(:wf_id, wf_filter.id) %>

  1. I did all steps as outlined in the doc.
  2. Since I am also using will_paginate, to avoid conflict, I added this to
    config/initializers/kaminari.rb

Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari

if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
def per(value = nil) per_page(value) end
def total_count() count end
end
end
module CollectionMethods
alias_method :num_pages, :total_pages
end
end
end
end


Reply to this email directly or view it on GitHub:
#28


Reply to this email directly or view it on GitHub:
#28 (comment)

@aprilw
Copy link

aprilw commented Oct 10, 2012

I'm also seeing this issue when I go to [mysite]/tr8n/admin/language.

@frane
Copy link

frane commented Nov 23, 2012

I've tracked the problem down to these two lines (821,822) in /app/models/will_filter/filter.rb :

 recs = recs.page(page).per(per_page)
 recs.wf_filter = self

The problem occurs when trying to replace kaminari with will_paginate, as will_paginate returns an ActiveRecord::Relation instead of an Array.
A possible solution is to materialize the results (convert AR:Relation to Array) like so:

 recs = recs.page(page).per(per_page).to_a

However, it appears that a lot more work is necessary to replace kaminari with will_paginate as #8 suggests. Nevertheless it would be nice to have the option to chose between will_paginate and kaminari soon.

bhushangahire added a commit to bhushangahire/will_filter that referenced this issue Dec 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants