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

polymorphic associations causes exception #385

Closed
alec-c4 opened this issue Apr 27, 2011 · 7 comments
Closed

polymorphic associations causes exception #385

alec-c4 opened this issue Apr 27, 2011 · 7 comments

Comments

@alec-c4
Copy link

alec-c4 commented Apr 27, 2011

Hi,
i have model called Flag
class Flag < ActiveRecord::Base
attr_accessible :report_type, :flaggeable_id, :flaggeable_type, :return_to
########## Associations
belongs_to :author, :class_name => "User"
belongs_to :flaggeable, :polymorphic => true
end

and when i attempting to access this model from rails_admin i see error

NoMethodError in RailsAdmin::MainsController#list

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map

Full traces - http://pastie.org/1840863
But, when i have commented line belongs_to :flaggeable, :polymorphic => true everything works fine.

Could you check please work with polymorphs?

@kaapa
Copy link
Collaborator

kaapa commented May 2, 2011

Thank you for the report!

This might be a duplicate of issue #370 which has been resolved by c948fe7. Could you try to update RailsAdmin and check if this one's fixed as well?

@alec-c4
Copy link
Author

alec-c4 commented May 3, 2011

Hi,
not fixed :( with

remote: git://github.com/sferik/rails_admin.git
revision: 5af47a1
specs:
rails_admin (0.0.1)
builder (> 2.1.0)
rails (
> 3.0.6)

@kaapa
Copy link
Collaborator

kaapa commented May 3, 2011

Do you have flaggeable parent models defined? With this I mean the has_many/has_one end of the association.

@alec-c4
Copy link
Author

alec-c4 commented May 3, 2011

Of course
class Issue < ActiveRecord::Base
has_many :flags, :as => "flaggeable", :dependent => :destroy
end

@kaapa
Copy link
Collaborator

kaapa commented May 3, 2011

Ok, does the problem go away if you declare parent as symbol

has_many :flags, :as => :flaggeable, :dependent => :destroy

@alec-c4
Copy link
Author

alec-c4 commented May 3, 2011

yes, works fine. Could you please fix it with declaration as string?

@alec-c4 alec-c4 closed this as completed May 3, 2011
@kaapa
Copy link
Collaborator

kaapa commented May 3, 2011

Closed by 0e2c1d4

jdmorani pushed a commit to gdslink/rails_admin that referenced this issue May 3, 2011
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

2 participants