Answer the question
In order to leave comments, you need to log in
Paperclip how to access instance variables?
Greetings! Help to access object variable inside textmark[:text] stylesheet. I need to make a text watermark with dynamic text.
has_mongoid_attached_file :image,
path: ':rails_root/public/uploads/:class/cars/:id/:style.:extension',
url: '/uploads/:class/cars/:id/:style.:extension',
styles: {
small: {
geometry: '640x400#',
processors: [:watermark, :textmark],
watermark_path: "#{Rails.root}/public/watermark.png",
position: 'Center',
textmark: {
text: "Вот сюда надо вывести car_id",
position: "SouthWest",
offset: "+10+10",
color: "white",
size: "20"
}
}
}
Answer the question
In order to leave comments, you need to log in
Use lambdas ( https://github.com/thoughtbot/paperclip#dynamic-st... You
can use any data from your model inside a lambda. For example:
has_mongoid_attached_file :image,
path: ':rails_root/public/uploads/:class/cars/:id/:style.:extension',
url: '/uploads/:class/cars/:id/:style.:extension',
styles: lambda { |your_model| your_model.generate_styles }
def generate_styles
{
small: {
textmark: {
text: car_id
}
}
}
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question