Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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??

like image 736
Justin Avatar asked Dec 02 '25 05:12

Justin


1 Answers

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).

like image 93
jeremy.clark Avatar answered Dec 08 '25 12:12

jeremy.clark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!