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

hbtm with order brokes edit page #2067

Closed
yahor opened this issue Sep 18, 2014 · 8 comments
Closed

hbtm with order brokes edit page #2067

yahor opened this issue Sep 18, 2014 · 8 comments
Milestone

Comments

@yahor
Copy link

yahor commented Sep 18, 2014

class Group < ActiveRecord::Base
has_and_belongs_to_many :users, -> { order last_name: :asc }
end

group edit page:
ArgumentError - wrong number of arguments (1 for 0):
rails_admin (0.6.3) lib/rails_admin/adapters/active_record/association.rb:61:in `read_only?'

@wefarrell
Copy link

Also seeing this error on the has and belongs to many association

@kenjione
Copy link

Have same problem with:

has_and_belongs_to_many :properties, -> { uniq }

@kenjione
Copy link

Guys, I found some solution which works:

I replaced -> to Proc.new :
has_and_belongs_to_many :properties, Proc.new { uniq }

@kaishin
Copy link

kaishin commented Feb 28, 2015

Having the same issue as well.

@yahor
Copy link
Author

yahor commented Feb 28, 2015

has_and_belongs_to_many :users, Proc.new { order last_name: :asc }
it works for me, thanks @kenjione

@CapnMorgan71
Copy link

Any updates on this? that did Proc new did not work for me.

@yushine
Copy link

yushine commented Oct 30, 2015

It works for me, thanks @kenjione .
And do you know what's the reason?

@lucas-nelson
Copy link

FWIW I just hit this in 0.8.1, changing the '->' to 'proc' enabled the rails_admin edit page to load. There seems to be no other side-effects, but it's a bit annoying because the official docs all point to lambdas as the way to add a scope to the relation.

Is there an alternative to instance_eval that does not pass the receiver as an argument?

PS: I also tried adding a param to the lambda which did enable the edit page to function, but I started getting this deprecation warning around my site (I sometimes preload the association):

DEPRECATION WARNING: The association scope 'tags' is instance dependent (the scope block takes an argument). Preloading happens before the individual instances are created. This means that there is no instance being passed to the association scope. This will most likely result in broken or incorrect behavior. Joining, Preloading and eager loading of these associations is deprecated and will be removed in the future.

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

8 participants