image_tag in markdown with paperclip

271 views Asked by At

I'm adding images in the text of my blog articles.

I have the BlogImage model:

class BlogImage < ActiveRecord::Base
  attr_accessible :blog_id, :caption, :image

  belongs_to :blog

  has_attached_file :image, styles: { big: "1200X630>", medium: "300x300>", thumb: "300x300>" }, default_url: "/images/:style/missing.png"

  validates_attachment_presence :image
  validates_attachment_size :image, :less_than => 3.megabytes
  validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png']
end

and my article body is rendered with:

    :markdown
      #{blog.body}

The markdown is handled by the gem rdiscount

I would like to be able to write a tag in my markdown, (such as [image_name] or similar) so that this would be automatically converted upon rendering with the right image tag.

I don't know where to start with.

Thanks.

1

There are 1 answers

1
David Foster On

You can insert an image with RDiscount using syntax like:

![GitHub Favicon](https://github.com/favicon.ico =16x16)

The title is required (but can be empty). The size is optional.