3

I have a has_and_belongs_to_many association between my Activity model and Photo Model.

class Activity < ActiveRecord::Base
  has_and_belongs_to_many :photos, -> { where(photos: { deleted: false })}
end

class Photo < ActiveRecord::Base
  has_and_belongs_to_many :activities
end

I have installed rails_admin for creating the admin pages for these models.

However when I try to access the 'admin/activity/new' page I get an error:

wrong number of arguments (1 for 0)

on the line where the has_and_belongs_to_many association is defined for photos.

When I remove the where condition from the association I am able to access the 'admin/activity/new'.

Is there any problem with where conditions on the has_and_belongs_to_many association with rails_admin or am I doing something wrong??

DanMatlin
  • 1,212
  • 7
  • 19
  • 37

1 Answers1

2

instead of -> you can use Proc.new

e.g.

has_and_belongs_to_many :photos, Proc.new { where(photos: { deleted: false })}

This worked for me

berkos
  • 51
  • 2