Justin
Justin

Reputation: 4940

Rails adding images to a Post

I have a Rails app for blog posts.

Each Post has a title and the blog_text. I want to be able to add images to the blog post as well while i'm creating the blog post. What's the correct way to do this?? Would I just create another migration to add blog_photos so the post has_many blog_photos??

Or should i install a good markdown editor for the blog_text??

Upvotes: 3

Views: 5259

Answers (1)

jeremy.clark
jeremy.clark

Reputation: 852

It depends on how the images are to be used. Here are two scenarios:

  1. The images are meant to be inside the blog text and added by the user. For this scenario I would use ckeditor (https://github.com/galetahub/ckeditor). This will give the user a WYSIWYG editor and allow them to upload images into the blog text (CKEditor will create two models for attachments).

  2. The images are specific header/icon images for a specific purpose and not contained in the blog text. In this scenario I would use either paperclip (https://github.com/thoughtbot/paperclip) or carrierwave(https://github.com/carrierwaveuploader/carrierwave) and depending on the specific use case would add the image directly to the post model or create a separate model BlogAttachment (if you need a one to many relationship).

Upvotes: 9

Related Questions