Skip to content

Instantly share code, notes, and snippets.

@kagemusha
Created February 16, 2012 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagemusha/1843388 to your computer and use it in GitHub Desktop.
Save kagemusha/1843388 to your computer and use it in GitHub Desktop.
rails_admin with renamed model in belongs_to assoc
Tested on: Rails 3.2.1
Will get error if don't add :foreign_key to has_many side of relat:
e.g.
class Song < ActiveRecord::Base
belongs_to :creator, :class_name=>"User" #person who added song entry
class User < ActiveRecord::Base
has_many :created_songs, :class_name=>"Song", :foreign_key => 'creator_id'
1. Here, User must have :foreign_key in its has_many statement
2. Make sure :class_name is a string!
:class_name=>:song will not work!!
https://github.com/sferik/rails_admin/blob/master/spec/dummy_app/app/models/league.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment