質問

I have a tidbit model that has a carrierwave uploader. Im working on attaching an inline image in an email. If I do this:

  @filename = @tidbit.image.instance_variable_get('@file').filename
  attachments.inline[@filename] = @tidbit.image.read

I get an inline image in my email. However, it is the full size original version.

How would I inline attach a specific version (i.e.. :thumb) of the image?

If I do:

  attachments.inline[@filename] = @tidbit.image(:thumb).read

I get an argument error 1 for 0.

役に立ちましたか?

解決

Late reply, but it might help googlers and I had to do something similar. The following worked:

These are the versions present on my uploader class

version :thumb do
  process :resize_to_fill => [122, 70]
end
version :medium do
  process :resize_to_fill => [470, 470]
end

So to get the image in a certain version I just need to do, for example:

specific_version = uploader.image.medium.read

Where medium is the version I want.

In the original question's case you need to do:

attachments.inline[@filename] = @tidbit.image.thumb.read
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top