Created
June 2, 2017 14:35
-
-
Save Naggi-Goishi/8f049779dc1d7251b5fe74fd5a96d4a6 to your computer and use it in GitHub Desktop.
STIとポリモーフォック関連は相容れない ref: http://qiita.com/Naggi-Goishi/items/8dc6345c4324ae34817d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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