This guide will help you to migrate from version 1.x to 2.x.
❗ Note: the gem uploadcare-rails 2.x is not backward compatible with 1.x.
- Configuration
- File Uploader widget settings
- Form builders support
- File and Group objects
- File methods
- Group methods
- Image URL transformations
- Useful links
The configuration file was moved to the config/initializers
directory in the version 2.x. So, if you have yml
file with options, please, run the config generator. It will create a new file config/initializers/uploadcare.rb
:
# with docker
$ docker-compose exec <web server service name> bundle exec rails g uploadcare_config
# without docker
$ bundle exec rails g uploadcare_config
and set there all your config options.
To start using the File Uploader widget you should add the uploadcare_include_tag
to the tag of the html-page.
In version 1.x this helper tag was called include_uploadcare_widget_from_cdn
.
# before
<%= include_uploadcare_widget_from_cdn version: "3.x", min: true %>
# after
<%= uploadcare_include_tag version: "3.x", min: true %>
The helper uploadcare_settings
is not needed anymore, all the global options for the widget is now taken from the config/initializers/uploadcare.rb
included in the uploadcare_include_tag
tag, so remove it from your views.
The helper uploadcare_uploader_field
was not changed.
You can use the helper either for File
and for Group
attributes of a model. Helper will automatically enable the multiple
option if you placed the mount_uploadcare_file_group
method in a model for that attribute.
No difference between single Uploadcare::File and Uploadcare::Group attributes for views:
<%= uploadcare_uploader_field :post, :logo %>
<%= uploadcare_uploader_field :post, :attachments %>
Form builders support was removed from the version 2.x. So, if you have some of the following helpers used in your views:
f.uploadcare_uploader :file
f.uploadcare_uploader :file, :data => {:multiple => true}
f.uploadcare_single_uploader_field :file
f.uploadcare_multiple_uploader_field :file
please, change it to:
uploadcare_uploader_field :model_name, :attribute_name
In the version 2.x mount_uploadcare_file :attribute_name
and mount_uploadcare_file_group :attribute_name
are added. Please, change old methods in your models if needed:
class Post < ApplicationRecord
# before
has_uploadcare_file :logo
has_uploadcare_group :attachments
# after
mount_uploadcare_file :logo
mount_uploadcare_file_group :attachments
end
Some methods were changed/removed for File and Group objects.
The method post.logo
will return Uploadcare::Rails::File
, not just an URL.
So if you need to get an URL, please, make following changes:
# before
post.logo
# after
post.logo.cdn_url
# OR
post.logo.to_s
The method image_tag(post.logo)
was removed in the version 2.x. So if you have to render images this way, please, make following changes:
# before
<%= image_tag(post.logo) %>
# after
<%= image_tag post.logo.cdn_url %>
OR
<%= image_tag post.logo.to_s %>
This all works same way for groups attribute (post.attachments
in Post
model example).
Showing group files was not changed much (urls -> file_urls
):
# before
<ul>
<%- @post.attachments.urls.each do |url|%>
<li>
<%= image_tag(url) %>
</li>
<% end %>
</ul>
# after
<ul>
<%- @post.attachments.file_urls.each do |url|%>
<li>
<%= image_tag(url) %>
</li>
<% end %>
</ul>
In the version 2.x image URL transformation methods names were changed.
# before
@post.logo.url(options)
@post.attachments.urls(options)
# after
@post.logo.transform_url(options)
@post.attachments.transform_file_urls(options)
Please, see the Changelog for more information about added/removed methods and features.