Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uploader class for carrierwave #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Nitr
Copy link
Contributor

@Nitr Nitr commented Feb 28, 2014

No description provided.

@ricbermo
Copy link

ricbermo commented Apr 9, 2014

This is a very nice feature, but, what if the user doesn't define any version?.

@Nitr
Copy link
Contributor Author

Nitr commented Apr 10, 2014

https://github.com/bastiaanterhorst/rich/blob/master/lib/rich.rb#L11
image_styles has default version always.
Did you mean it?

@ricbermo
Copy link

Yes, sorry, my fault. didn't see that. may I ask you something, are you getting an error with fog when you use amazon s3 as storage?. I'm getting one weird error.

@Nitr
Copy link
Contributor Author

Nitr commented Apr 10, 2014

I don't use fog yet(with rich). Error from amazon or rich code? Show me messages! =)
And now I think, use rich in production is not good idea, because no specs. =(

@ricbermo
Copy link

Hi, i was about to update my comment, this is what is causing the "fog" problem; it's not fog actually,
https://github.com/BrandyMint/rich/blob/nitr/feature/carrierwave_uploader/lib/rich/backends/carrierwave.rb#L41

@ricbermo
Copy link

I could find the error I was trying to let you know before, if I don't include

version :rich_thumb do
    process :resize_to_fit => [100, 100]
end

in my custom uploader I get this error:
undefined method `version' for Rich::Backends::CarrierWave::DefaultCarrierwaveVersions:Module (NoMethodError)

This is also happening when I set a custom version in my uploader

@ricbermo
Copy link

I change your code to this

module DefaultCarrierwaveVersions
  Rich.image_styles.each do |name, size|
    unless Rich.uploader.constantize.versions.include? name
      Rich.uploader.constantize.send :version, name.to_s do
        process :resize_to_fit => size.gsub("#", "").split("x").map(&:to_i)
       end
    end
  end
end

and now the versions are working (the ones you set in rich initializer and removing the versions from my custom uploader)

@Nitr
Copy link
Contributor Author

Nitr commented Apr 10, 2014

And yet I think, making preview image(rich_thumb) with PaperClip or Carrierwave is not good. We need add to model RichFile column preview, which will not be depend of image_styles and any image uploaders.

@ricbermo
Copy link

My friend, there's something new that you should change in your commit in order to make it work with fog and your custom uploader.

def uri_cache
  uri_cache_attribute = read_attribute(:uri_cache)
  if uri_cache_attribute.blank?
    uris = {}

    rich_file.versions.each do |version|
      uris[version[0]] = rich_file.url(version[0].to_sym)
    end

    #manualy add the original size
    uris["original"] = rich_file.url

    uri_cache_attribute = uris.to_json
    rich_file.model.update_attribute(:uri_cache, uri_cache_attribute)
  end
  uri_cache_attribute
end

Please, add a comment to your PR to let know that this pull requests allows amazon S3 as storage too.

@ricbermo
Copy link

Another thing, you cannot use the same uploader for images and files :/

@leofrozenyogurt
Copy link

Are we going to be able to use S3 then with this merge?

@ricbermo
Copy link

yes. the uploader can be configured in order to use S3.

@leofrozenyogurt
Copy link

any direction to this?
i currently have config.backend = :carrierwave
and my carrierwave initializer set up for fog/s3 storage

@ricbermo
Copy link

to be honest I don't remember but I'd say that it's exactly how you did it. Set up your backend to carrierwave, set the name of your carrierwave uploader and config your uploader with fog to use S3. Check the code to be sure.

@leofrozenyogurt
Copy link

Ahhh how do you set up the name of the carrierwave uploader in rich.

I have an uploader called ImageUploader which uses fog for my other images but how can i get fog to use this as well?

@ricbermo
Copy link

@leofrozenyogurt
Copy link

tried this
config.uploader :rich_file_file_name, ImageUploader
and it still didnt work

@ricbermo
Copy link

my friend, I think the correct config is
config.uploader: "ImageUploader"

@leofrozenyogurt
Copy link

that didnt work either.

So i set fog as global store but i am now getting this error

NoMethodError - undefined method `merge' for false:FalseClass:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants