简体   繁体   中英

image_tag in markdown with paperclip

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM