url override with version

453 views
Skip to first unread message

Jan Limpens

unread,
Oct 25, 2010, 4:07:48 PM10/25/10
to carrierwave
Hello,

I have an uploader with an url override like this:

def url
"#{APP_CONFIG["images_virtual_root"]}/article/#{model.cached_slug}/
#{filename}"
end

how can I enable versions with that The Good Way?

--jan

Jonas Nicklas

unread,
Oct 25, 2010, 4:13:35 PM10/25/10
to carri...@googlegroups.com
Why do you want to override the url?

/Jonas

> --
> You received this message because you are subscribed to the Google Groups "carrierwave" group.
> To post to this group, send email to carri...@googlegroups.com.
> To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.
>
>

Jan Limpens

unread,
Oct 25, 2010, 8:57:27 PM10/25/10
to carri...@googlegroups.com
it's different from store_dir...
--
Jan

Jan Limpens

unread,
Oct 26, 2010, 12:41:10 PM10/26/10
to carri...@googlegroups.com
Am I misunderstanding something? How does one come around the situation where store_dir does not directly map to url (in my situation, it points to a different host)? I thought, overrifing url was the way to go - and it is, if there weren't for the versions...
--
Jan

Jonas Nicklas

unread,
Oct 26, 2010, 3:55:19 PM10/26/10
to carri...@googlegroups.com
Yes, that seems like a legitimate reason to override #url. There's a
ton of cases where it does not make sense, so I was just making sure.

There are a lot of moving parts here and a lot of it depends on how
your storage solution works. Are you using the file store, or a
different store? This is how #url is implemented in CarrierWave:

def url
if file.respond_to?(:url) and not file.url.blank?
file.url
elsif current_path
File.expand_path(current_path).gsub(File.expand_path(root), '')
end
end

As you can see it uses current_path unless the file itself responds to
#url (which it should for all storage engines except for file
storage). This is for good reason: filename works pretty
unintuitively, it does not actually *return* the file's filename,
rather it's used to *construct* the filename of the newly uploaded
file. If you want the *actual* filename, I'd suggest doing something
like File.basename(current_path), this will be much more reliable, and
should also work with versions. Again, this only works with the file
store, if you use any other store, then you can't use current_path,
because it will most likely return nothing, or at least nothing
particularly useful.

/Jonas

Jan Limpens

unread,
Oct 26, 2010, 8:14:54 PM10/26/10
to carri...@googlegroups.com
I am completely fine with a _constructed_ filename. It just seems to me that I would rather have to override url(*args) which seems to pick up versions. It's just so that my ruby newbeeness leaves me confused on how to reasonably override these methods that pop up in my classes "out of nowhere".

I am using file storage.

Jan Limpens

unread,
Oct 27, 2010, 9:10:52 PM10/27/10
to carri...@googlegroups.com
Currently I put this into the model:

  #hack - this should go to the uploader
  def ambient_picture_uri(size=nil)
    ambient_picture_url ? ambient_picture_url(size).gsub(APP_CONFIG["images_fs_root"], APP_CONFIG["images_virtual_root"]) : nil
  end

but as the comment says...
How could I do that?

--j
--
Jan
Reply all
Reply to author
Forward
0 new messages