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

scopes in list view not work with RA 0.6.6 #2143

Closed
fmh opened this issue Dec 28, 2014 · 5 comments
Closed

scopes in list view not work with RA 0.6.6 #2143

fmh opened this issue Dec 28, 2014 · 5 comments

Comments

@fmh
Copy link
Contributor

fmh commented Dec 28, 2014

undefined method `each' for nil:NilClass
Showing /Users/xxxx/MyHomeCloud/Dev/MyApp/app/views/rails_admin/main/index.html.haml where line 128 raised:

capture d ecran 2014-12-28 a 21 05 52

@fmh fmh changed the title scopes not work with RA 0.6.6 scopes in list view not work with RA 0.6.6 Dec 28, 2014
@mshibuya
Copy link
Member

I think your custom scope(probably class method?) might be returning nil.
Can you paste your model and RailsAdmin configuration?

@fmh
Copy link
Contributor Author

fmh commented Dec 29, 2014

class Product < ActiveRecord::Base
   acts_as_tenant(:tenant)
  scope :p , -> {where("securekey is not null")}
  scope :s ,  -> {where("securekey is null")}

 rails_admin do
    object_label_method do
      :to_label
    end
 list do
      scopes  [:p, :s, nil]
      field :price
      field :parent
    end
end
end

@mshibuya
Copy link
Member

This is weird. In Rails console,

Loading development environment (Rails 4.2.0)
2.1.5 :001 > Product.all.send(:p)
 => nil
2.1.5 :002 > Product.all.p
D, [2014-12-30T11:24:02.619010 #32919] DEBUG -- :   Product Load (2.1ms)  SELECT "products".* FROM "products" WHERE (securekey is not null)
 => #<ActiveRecord::Relation []>
2.1.5 :003 > Product.all.send(:p)
D, [2014-12-30T11:24:05.381362 #32919] DEBUG -- :   Product Load (0.2ms)  SELECT "products".* FROM "products" WHERE (securekey is not null)
 => #<ActiveRecord::Relation []>

As you can see, first send(:p) is returning nil, while after hitting Product.all.p it works as expected. I'll try to see if Rails team has already resolved this issue.

For now, you can use a scope name other than :p to avoid method name collision(yes, the name p collides with Ruby's Kernel#p) as a workaround.

@fmh
Copy link
Contributor Author

fmh commented Dec 30, 2014

thx :)

@neyp
Copy link

neyp commented May 11, 2015

Any news on this one? Mine doesn't work either with v0.6.5. The scopes array is simply ignored and the tabs just don't show up. I'm using Ruby 2.1.5 and Rails 4.1.8.

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

3 participants