carrierwave-serializable icon indicating copy to clipboard operation
carrierwave-serializable copied to clipboard

[Feature Request] Need a convenient method to get original field real value

Open zw963 opened this issue 10 years ago • 3 comments

Some times, I will import some image data from rake task, so, my mounted image field will have a http://some_site/some_image.png value.

so,I will handle this situation with override uploader url method like this:

  def url
     # here, if not use a serialize field, model[mounted_as] will get the original value.
    original_url = model[mounted_as]

    original_url =~ %r{\Ahttps?://} ? original_url : super
  end

But if use serialize, model[mounted_as] or model.read_attribute[mounted_as is not worked anymore,we need a new api to get the correct value.

currently, I have to do like this:

  def url
    serialize_to = model.class.serialized_uploaders[mounted_as]
    original_url = model[serialize_to][mounted_as.to_s]

    original_url =~ %r{\Ahttps?://} ? original_url : super

  end

Here, if can expose a original_url API, is good. Thanks.

zw963 avatar Oct 21 '15 03:10 zw963

It is probably a bit late, but feel free to open a PR with the proposed change

timfjord avatar Apr 14 '21 09:04 timfjord

Long long ago ... i am afraid forget why create this issue ...

zw963 avatar Apr 14 '21 09:04 zw963

😄 I am going to keep it for now, maybe someone else will be interested in it

timfjord avatar Apr 14 '21 15:04 timfjord