submodel, subclass or subcontroller ruby on rails references -
i busy making ruby on rails app.
i want make model contains text model, picture model , link model. every model can have comments, don't want make different comment models text, picture , link model. possible make media model witch has subclass(or how called) aka: picture model, text model , link model. or there other clean way this. thanks
you can create comment model has polymorphic association:
# comment model belongs_to :commentable, :polymorphic => true # other model should has comments has_many :comments, :as => :commentable
you can add above line every model needs comments. in order have polymorphic association need have columns in comments table in db:
commentable_id - int commentable_type - string
you can use plugin comments, on example this.
Comments
Post a Comment