2

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.

Don Giulio
  • 2,946
  • 3
  • 43
  • 82

1 Answers1

1

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.

David Foster
  • 6,931
  • 4
  • 41
  • 42
  • yeah that might be a solution, although paperclip generates complex filenames containing hashes, and I don't want to be searching for these complicate urls. So I'd really prefer something like: `(![GitHub Favicon]([favicon] =16x16)` and have the view replace that with the right url. – Don Giulio Jun 09 '14 at 15:44