I am trying to create a system in which users of my site can use selected pages. These pages have two types: clubs or sports. So, I have four models connected as such:
User Model:
class User < ActiveRecord::Base .. has_many :favorites has_many :sports, :through => :favorites has_many :clubs, :through => :favorites .. end
Featured Model:
class Favorite < ActiveRecord::Base .. belongs_to :user belongs_to :favoritable, :polymorphic => true end
Club Model:
class Club < ActiveRecord::Base .. has_many :favorites, :as => :favoritable has_many :users, :through => :favorites def to_param slug end end
Sports Model:
class Sport < ActiveRecord::Base .. def to_param slug end .. has_many :favorites, :as => :favoritable has_many :users, :through => :favorites .. end
In fact, the user has several sports or clubs through favorites, and the association between favorites, sports and clubs is polymorphic.
In practice, everything works exactly the way I want, and the whole system that I developed works. However, I use Rails_Admin on my site, and I get an error message in three places:
- At the first boot of the control panel (/ admin). If I refresh the page, it works great.
- When loading user model in Rails_Admin
- When loading the Favorites model in Rails_Admin
Here is the error message /admin/user (gist) . All errors are similar, referring to ActiveRecord::Reflection::ThroughReflection#foreign_key delegated to source_reflection.foreign_key, but source_reflection is nil:
Can someone point me in the right direction so that I can fix it? I searched around and asked other programmers / professionals, but no one could detect an error in my models. Thank you very much!