rails-activestorage

Rails Active Storage not display @user.banner_image [duplicate]

随声附和 提交于 2019-12-13 03:56:18
问题 This question already has answers here : to_model delegated to attachment, but attachment is nil (2 answers) Closed 3 months ago . So I've been playing with rails active storage lately and came across an issue. user.rb class User < ApplicationRecord has_one_attached :banner_image end show.html.haml .profile-header = @user.banner_image in return i get this error: Can't resolve image into URL: to_model delegated to attachment, but attachment is nil Extracted source (around line #2): .profile

Rails 5.2 Active Storage with Cocoon forms

白昼怎懂夜的黑 提交于 2019-12-12 16:33:24
问题 I want to save some images to a model using a dynamic cocoon form with Active Storage to handle the files. I have a farmer class that has many apples, the farmer can add multiple images for each of the different kinds of apples through the farmer form. class Farmer < ActiveRecord::Base has_many :apples, inverse_of: :farmer accepts_nested_attributes_for :apples, allow_destroy: true, reject_if: :all_blank end class Apple < ActiveRecord::Base has_many_attached :apple_images end Inside the Farmer

How to load images/precompiled assets with PDFKit/wkhtmltopdf? Rails 5.2

孤者浪人 提交于 2019-12-11 18:22:37
问题 I'm having some success with creating PDFs with PDFKit, but the images are not loading from active_storage and assets resources. It fails every single time that I create the PDF, using show.pdf.erb. I'm using the default image_tag and assets are precompiled for production. How can I get PDFKit to find the precompiled assets folder for the images, and also find active_storage images that are supposed to load within the show.pdf.erb view? It works perfectly fine in the normal show.html.erb

heroku push suddenly failing

…衆ロ難τιáo~ 提交于 2019-12-11 15:43:29
问题 I pushed out to heroku last night, and now today my pushes are failing with the following error. Heroku status appears to be ok. My heroku config has RAILS_MASTER_KEY set to my master.key. That did not help. Any experience this...or, able to point me towards a fix? Command: 'bin/rails runner "puts %Q{heroku_detecting_active_storage_config=#{Rails.application.config.active_storage.service}}"' failed unexpectedly: remote: ! Missing encryption key to decrypt file with. Ask your team for your

Rspec : stubbing ActiveStorage download method

青春壹個敷衍的年華 提交于 2019-12-11 02:31:39
问题 I work on a system that stores cached data on S3 with ActiveStorage before using it for something else. In my spec, I want to stub the download method of this file, and load a specific file for testing purpose. allow(user.cached_data).to receive(:download) .and_return(read_json_file('sample_data.json')) ( read_json_file is a spec helper that File.read then JSON.parse a data file.) I get this error : #<ActiveStorage::Attached::One:0x00007f9304a934d8 @name="cached_data", @record=#<User id: 4,

Rails ActiveStorage url_for returns an URL which is not valid

十年热恋 提交于 2019-12-10 19:28:27
问题 I have an Employee model with an Avatar. I can attach an image to the avatar, but whenever I try to display the image, the url_for(@employee.avatar) produces a dead link. All I'm seeing is the value from the alt attribute from the tag. The image tag I'm getting is the following <img src="/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--4786aa4d9d82d8f8d572b857965088b20fcb2f49/Portrait.jpg" alt="Thumbnail"> And I know the image has

ActiveStorage for S3 private files

可紊 提交于 2019-12-10 18:43:09
问题 Until now I was using Paperclip for uploading some files to S3. Some of these files are not public and Paperclip allowed to upload some files as private with the following bit : has_attached_file :image, styles: { large: "2000x2000", small: "1200x1200", thumb: "250x250"}, :s3_permissions => :private Now Paperclip is deprecated I am considering switching to Active Storage though I have not found any option to make some of my files private. Is there something to tweak in Active Storage to allow

Change default url from Active Storage

允我心安 提交于 2019-12-09 06:45:43
问题 Can we change the default 'permanent' url create from active storage to redirect to S3. Is something like rails/active_storage/representations/. I don't like the framework name in the url. Thanks 回答1: UPDATE : Recently, there was an addition which makes the route prefix configurable: https://github.com/rails/rails/commit/7dd9916c0d5e5d149bdde8cbeec42ca49cf3f6ca Just in master branch now, but should be integrated into ~> 5.2.2 and higher. Then, it's just a matter of configuration: Rails

Rails Active storage Unable to autoload constant ActiveStorage::Blob::Analyzable

坚强是说给别人听的谎言 提交于 2019-12-08 03:12:47
问题 I've updated rails from 5.1.4 to 5.2 and remove Papaerclip to use Active Storage. I'm using digitalocean spaces. In my development env I've setted credentials in storage.yml to save images to digitalocean. I've added aws-sdk-s3 gem in gemfile (without version, may be this the problem?). I run db:migrate for active storage. But when I'm going to submit the form with an image upload html tag, i receive this error: Unable to autoload constant ActiveStorage::Blob::Analyzable. Anyone can help me?

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

给你一囗甜甜゛ 提交于 2019-12-07 18:14:12
问题 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 >): 回答1: Solution: