rails-activestorage

Blob Error with Active Storage Rails 5.2

谁说胖子不能爱 提交于 2019-12-07 06:56:43
问题 I've just upgraded a 5.1.4. app to 5.2 and am trying to swap out Paperclip for ActiveStorage. At the moment when trying to update an existing record with an image, I get the following error: Unable to autoload constant ActiveStorage::Blob::Analyzable, expected /Users/Simon/.rvm/gems/ruby-2.4.0/gems/activestorage-5.2.0/app/models/active_storage/blob/analyzable.rb to define it In my model: has_one_attached :pic In my controller: ... def update respond_to do |format| if @gin.update(gin_params)

Can't resolve image into URL: to_model delegated to attachment, but attachment is nil Rails 5.2

牧云@^-^@ 提交于 2019-12-07 06:41:36
问题 I have the following form: <%= form_with(model: user, local: true) do |form| %> <% if user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% user.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= form.file_field :avatar %> </div> <div class="actions"> <%= form.submit %> </div> <% end %> It is being called on my edit page: <h1

Rails ActiveStorage Error - MessageVerifier-InvalidSignature

不打扰是莪最后的温柔 提交于 2019-12-07 04:40:55
问题 I'm working on a project that requires an ActiveStorage has_many_attached :photos situation on a Location model. I have the code set up below, but when attempting to upload a form, I receive the following error: ActiveSupport::MessageVerifier::InvalidSignature in LocationsController#attach_photo Is this the way to "add" a file to the set of attachments for a particular parent record (i.e: a Location record)? Location Model class Location < ApplicationRecord ... has_many_attached :photos ...

How can I upload an image to S3 with rails' Active Storage from a <canvas /> in a rails form?

ⅰ亾dé卋堺 提交于 2019-12-06 08:17:07
问题 As stated in the title I'm trying to upload an image to my S3 bucket with rails' Active Storage from a element that is nested within a rails form. So far I've been able to use <%= f.input :signature, type: file_field(:user, :signature), %> to upload an image with Active Storage. The User class has_one_attached :signature . The images upload correctly when I use a file_field, so that's not part of the problem. So far my simple_form has: <div class="signature_pad text-center form-group"> <div

Can't get past error in Rails Setup- `LoadError: cannot load such file — active_storage/engine`

我的梦境 提交于 2019-12-06 08:08:45
问题 I'm trying to setup a new Rails application and having an issue that I can't seem to resolve. When trying to run rake db:drop or rake db:create I keep getting the error: LoadError: cannot load such file -- active_storage/engine At first I was getting an error: LoadError: cannot load such file -- bootsnap/setup but was able to clear that after adding it to my gemfile. I see some info on Github that suggests uncommenting require "active_storage/engine" but I've already done that. Not sure what

How can I access an ActiveStorage object via URL in a test environment?

主宰稳场 提交于 2019-12-06 07:52:29
Given a model that has an ActiveStorage attachment class MyObject has_one_attached :avatar end In a dev environment I am able to retrive the avatar as a StringIO object. obj = MyObject.new( { valid params } ) file = File.open( Rails.root.join( "spec/support/images/test_image.jpg" )) obj.avatar.attach( io: file, filename: "test_image.jpg" ) obj.save version = obj.avatar.variant( resize: '200x200>').processed version_url = Rails.application.routes.url_helpers.url_for( version ) download = open(version_url) download.class => StringIO When I attempt to do the same think in a test environment, open

Rails 5.2.1 ActiveStorage file downloads with nginx/puma are truncated

人盡茶涼 提交于 2019-12-06 03:55:57
My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files . For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download. I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine. All environments use the config.active_storage.service = :local config/storage.yml local: service: Disk root: <%= Rails.root.join("storage") %> Download url is generated using rails_blob_path(document.doc, disposition: :inline) I suspect

How can I get url of image variant in model (outside of controller/view)? Active Storage

自闭症网瘾萝莉.ら 提交于 2019-12-05 20:19:55
I can get url in model with this code (Active Storage) Rails.application.routes.url_helpers.rails_blob_path(picture_of_car, only_path: true) But I need get url of resized varian picture_of_car.variant(resize: "300x300").processed For example this code Rails.application.routes.url_helpers.rails_blob_path(picture_of_car.variant(resize: "300x300").processed, only_path: true) throw NoMethodError (undefined method `signed_id' for #< ActiveStorage::Variant:0x0000000004ea6498 >): Solution: Rails.application.routes.url_helpers.rails_representation_url(picture_of_car.variant(resize: "300x300")

Can't resolve image into URL: to_model delegated to attachment, but attachment is nil Rails 5.2

落爺英雄遲暮 提交于 2019-12-05 11:58:23
I have the following form: <%= form_with(model: user, local: true) do |form| %> <% if user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% user.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= form.file_field :avatar %> </div> <div class="actions"> <%= form.submit %> </div> <% end %> It is being called on my edit page: <h1>Upload Avatar</h1> <%= image_tag(@user.avatar) %> <%= render 'form', user: @user %> <hr> I get the error

ActiveStorage to upload large base64 encoded string?

。_饼干妹妹 提交于 2019-12-05 09:18:52
If I have an image that was edited/generated using JavaScript on the client (for example, a cropped photo or the result of a canvas drawing), is there a way to upload it using ActiveStorage? It would typically be a large string containing "<img src='data:image/jpeg;base64,...=='>" that is stored in a JavaScript variable, not a file. As far as I know, Active Storage has currently no native support for that. Maybe this Rails issue has further information helpful to you. We have implemented Data URI uploads with Shrine (and its DataURI Plugin ) and are waiting until there is a proper way to do