gregbell/active_admin — Issue #759: undefined method `build' for #<Class:0x000001011bf448>
Author: cgunnels
Created: 2011-11-17 21:17:17+00:00
State: open

not sure what's going on here but I am getting this message when I am trying to create a new record. In my active admin controller I have a scope_to like:

scope_to :current_user, :association_method => "association_#{config.resource}_for_user"

In my user model I have the following to handle the association method:

def method_missing(meth, *args, &block)
if meth.to_s =~ /^association_(.*)_for_user$/
set_up_query_for_resource($1.constantize)
else
super
end
end

def set_up_query_for_resource(resource)
return resource if is?(:admin)

if resource.new.respond_to?(:user_id)
resource.where(:user_id => id)
else
resource.includes(:user).where("users.id = ?", id)
end
end

Let say my association method in the scope_to method is association_Domain_for_user and I am logged in as an admin, the first line in set_up_query_for_resource method will return Domain. Then it seems as though active admin will call Domain.build. Is this correct? I am stuck at this point and don't know what to do. Any ideas?