I am writing a RoR application with a blog. Each blog may have several pictures. The number of pictures is unknown.

I'm going to use paperclip to load images.

All the examples that I found bind to the record one picture, and this is the field of the model.

How to organize a model or a set of models so that several images can be displayed in one blog? And how to organize it when writing a blog through markdown markup.

Please give links to examples, or tell me how?

    1 answer 1

    How to organize a model or a set of models so that several images can be displayed in one blog? And how to organize it when writing a blog through markdown markup.

    You need to create a separate model for images.

    class Picture < ActiveRecord::Base belongs_to :blog has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png" validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/ end class Post < ActiveRecord::Base has_many :pictures end 

    Well, add the appropriate migration http://rusrails.ru/active-record-associations#svyaz-has_many