Skip to content

Instantly share code, notes, and snippets.

@Naggi-Goishi
Created June 2, 2017 14:35
Show Gist options
  • Save Naggi-Goishi/8f049779dc1d7251b5fe74fd5a96d4a6 to your computer and use it in GitHub Desktop.
Save Naggi-Goishi/8f049779dc1d7251b5fe74fd5a96d4a6 to your computer and use it in GitHub Desktop.
STIとポリモーフォック関連は相容れない ref: http://qiita.com/Naggi-Goishi/items/8dc6345c4324ae34817d
class User < ActiveRecord::Base
end
class Admin < User
has_many :images, as: :imageable
end
class NormalUser < User
has_many :images, as: :imageable
end
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
end
def open_image(user)
user.image.open
end
open_image(admin_user)
open_image(normal_user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment