Take Proc object as a value [Feature Request]
I'm trying to cache a URL for an image of my product in my project_products model
So I'm trying something like this:
class ProjectProduct
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Alize
field :quantity, type: Integer
field :notes, type: String
belongs_to :product
embedded_in :project
alize :product, :name, :slug, small_file: ->(p){p.url(:small)}
end
The key part is small_file: ->(p){p.url(:small)}. Since URL is actually computed based on the product_id and the size of the image (:small), Saving the file_name itself won't work.
It would be great if mongoid_alize would take a proc object and eval it on save.
Thoughts?
A workaround for this is to make a method that does the computation and use this:
class Product
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, ImageUploader
def small_file
file.url(:small)
end
end
and in the ProjectProduct I put alize :product, :name, :slug, :small_file
Thanks for opening the issue. I'd be happy to support that in a pull request.
As far as a workaround today, have you tried overriding the callback?