rails-activestorage

Blob Error with Active Storage Rails 5.2

时光毁灭记忆、已成空白 提交于 2019-12-05 09:13:12
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) format.html { redirect_to @gin, notice: 'Gin was successfully updated.' } format.json { render :show,

Rails ActiveStorage Error - MessageVerifier-InvalidSignature

只谈情不闲聊 提交于 2019-12-05 08:14:21
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 ... end Locations Controller class LocationsController < ApplicationController ... def attach_photo

Rails Read csv file data with active storage

自闭症网瘾萝莉.ら 提交于 2019-12-05 02:37:51
I have this class and I am using active storage class MaterialsUpload < ApplicationRecord has_one_attached :csv_file end This is the attachment #<ActiveStorage::Attached::One:0x007ff1f0be9e90 @dependent=:purge_later, @name="csv_file", @record= #<MaterialsUpload:0x007ff1f0c604f0 id: 3, success: 0, errors_list: [], total: 0, created_at: Mon, 12 Feb 2018 14:43:35 UTC +00:00, updated_at: Mon, 12 Feb 2018 14:43:35 UTC +00:00>> Is there a way I can read the data so I can do something like this string = materials_upload.csv_file.read CSV.parse(csv_string, headers: true) do |row| # do something end

Rails 5.2 Active Storage add custom attributes

让人想犯罪 __ 提交于 2019-12-04 16:58:04
问题 I have a model with attachments: class Project < ApplicationRecord has_many_attached :images end When I attach and save the image I also want to save an additional custom attribute - display_order (integer) with the attached image. I want to use it to sort the attached images and display them in the order I specified in this custom attribute. I've reviewed ActiveStorage source code for #attach method as well as ActiveStorage::Blob model but it looks like there is no built in method to pass

Active Storage with Amazon S3 not saving with filename specified but using file key instead

梦想与她 提交于 2019-12-04 13:49:54
I am having an issue with Active Storage. When I upload to Amazon S3, instead of saving the file inside the bucket with the original name like myfile.zip it is saving it as the key which is associated with that file. So in Cyberduck I am seeing something like this: 5YE1aJQuFYyWNr6BSHxhQ48t . Without any file extension. I am not sure if there is some setting in Rails 5 or whether it is within Amazon S3 but I have spent hours Googling around to figure out why this is happening. Any pointers would be really appreciated! Best regards, Andrew This is by design, from ActiveStorage. The file is

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

天涯浪子 提交于 2019-12-04 13:20:37
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 class="signature_pad_heading"> Enter your Signature: </div> <div class="signature_pad_body"> <canvas id=

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

北城以北 提交于 2019-12-04 12:46:56
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 to do. I got this error whilst downgrading my app from rails 6.0 to 5.2 Check in your config

How to save an image from a url with rails active storage?

假如想象 提交于 2019-12-04 12:14:20
问题 I'm looking to save a file (in this case an image) located on another http web server using rails 5.2 active storage. I have an object with a string parameter for source url. Then on a before_save I want to grab the remote image and save it. Example: URL of an image http://www.example.com/image.jpg. require 'open-uri' class User < ApplicationRecord has_one_attached :avatar before_save :grab_image def grab_image #this indicates what I want to do but doesn't work downloaded_image = open("http:/

How to get url of Active Storage image

▼魔方 西西 提交于 2019-12-03 12:11:08
问题 I want to get list of records with attached images as a links or files by api. I have a simple model: class Category < ApplicationRecord has_one_attached :image validates :name, presence: true, uniqueness: true end And next action: def index @categories = Category.all.with_attached_image render json: @categories.to_json(include: { image_attachment: { include: :blob } }) end That's the only way I can get image object. And I see next results: {"id":4,"name":"Cat1","description":""}, {"id":1,

How to get url of Active Storage image

倾然丶 夕夏残阳落幕 提交于 2019-12-03 06:57:59
I want to get list of records with attached images as a links or files by api. I have a simple model: class Category < ApplicationRecord has_one_attached :image validates :name, presence: true, uniqueness: true end And next action: def index @categories = Category.all.with_attached_image render json: @categories.to_json(include: { image_attachment: { include: :blob } }) end That's the only way I can get image object. And I see next results: {"id":4,"name":"Cat1","description":""}, {"id":1,"name":"Cat2","description":"","image_attachment": {"id":8,"name":"image","record_type":"Category","record