ruby-on-rails-5.2

Remove all data from Active Storage?

妖精的绣舞 提交于 2019-12-01 19:32:15
I would like to know how can I delete all data from Active Storage or even resetting Active Storage? There is any way to do that? Thank you in advance! NOTE: I'm using Rails 5.2 This question challenged me, so I did some test on my dummy app with local storage. I have the usual model User which has_one_attached :avatar On local storage files are saved on /storage folder, under subfolders named randomly with a string of two characters. Informations related to files are stored in two tables: ActiveStorage::Attachment ActiveStorage::Blob To completely clean the two tables , I did in rails console

Missing secret_key_base for 'production' environment,

ⅰ亾dé卋堺 提交于 2019-11-30 17:29:23
I simply cant get past the message Missing secret_key_base for 'production' environment, set this string with rails credentials:edit (ArgumentError) I have here rails 5.2.0. Ran EDITOR=vim rails credentials:edit and inside: production: secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx Save and, in terminal: RAILS_ENV=production rails c Am I missing something? Ive restarted server and same issue. No issue in development mode. Keep default the secrets.yml file # config/secrets.yml production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> RAILS_ENV=production SECRET_KEY_BASE=production_test_key rails c

Active Storage: Best practice to retain/cache uploaded file when form redisplays

橙三吉。 提交于 2019-11-30 12:59:57
When uploading files with Active Storage, when a file is finished uploading and the form gets redisplayed, for example when the validation for that form fails for some reason, the file is gone. Is there a way to cache or retain it between form redisplays? Shrine has a nice Plugin for that purpose, I'm looking for something similar for Active Storage. Here's a solution to make ActiveStorage files persist on form redisplay: f.hidden_field :image, value: f.object.image.signed_id if f.object.image.attached? f.file_field :image 来源: https://stackoverflow.com/questions/50360307/active-storage-best

Disable Active Storage in Rails 5.2

风流意气都作罢 提交于 2019-11-30 06:43:07
问题 Upgrading Rails to 5.2, and I found out that I must commit the storage.yml into version control. I don't plan to use ActiveStorage. Is there a way to disable it? 回答1: Remove next line from config/application.rb require "active_storage/engine" Remove next line from environments config/environments/*.rb config.active_storage.service = :local Remove next line from app/assets/javascripts/application.js //= require activestorage ActiveStorage rails routes will vanish In case there is statement

Missing secret_key_base for 'production' environment,

空扰寡人 提交于 2019-11-30 01:30:39
问题 I simply cant get past the message Missing secret_key_base for 'production' environment, set this string with rails credentials:edit (ArgumentError) I have here rails 5.2.0. Ran EDITOR=vim rails credentials:edit and inside: production: secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx Save and, in terminal: RAILS_ENV=production rails c Am I missing something? Ive restarted server and same issue. No issue in development mode. 回答1: Keep default the secrets.yml file # config/secrets.yml production:

Active Storage: Best practice to retain/cache uploaded file when form redisplays

百般思念 提交于 2019-11-29 18:33:56
问题 When uploading files with Active Storage, when a file is finished uploading and the form gets redisplayed, for example when the validation for that form fails for some reason, the file is gone. Is there a way to cache or retain it between form redisplays? Shrine has a nice Plugin for that purpose, I'm looking for something similar for Active Storage. 回答1: Here's a solution to make ActiveStorage files persist on form redisplay: f.hidden_field :image, value: f.object.image.signed_id if f.object

Disable Active Storage in Rails 5.2

こ雲淡風輕ζ 提交于 2019-11-28 21:22:56
Upgrading Rails to 5.2, and I found out that I must commit the storage.yml into version control. I don't plan to use ActiveStorage. Is there a way to disable it? Remove next line from config/application.rb require "active_storage/engine" Remove next line from environments config/environments/*.rb config.active_storage.service = :local Remove next line from app/assets/javascripts/application.js //= require activestorage ActiveStorage rails routes will vanish In case there is statement require 'rails/all' in application.rb then you can use solution provided below where you need to require

DEPRECATION WARNING: Dangerous query method: Random Record in ActiveRecord >= 5.2

白昼怎懂夜的黑 提交于 2019-11-28 00:40:29
So far, the "common" way to get a random record from the Database has been: # Postgress Model.order("RANDOM()").first # MySQL Model.order("RAND()").first But, when doing this in Rails 5.2, it shows the following Deprecation Warning: DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "RANDOM()". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql()

How to specify a prefix when uploading to S3 using activestorage's direct upload?

半腔热情 提交于 2019-11-27 14:10:50
With a standard S3 configuration: AWS_ACCESS_KEY_ID: [AWS ID] AWS_BUCKET: [bucket name] AWS_REGION: [region] AWS_SECRET_ACCESS_KEY: [secret] I can upload a file to S3 (using direct upload) with this Rails 5.2 code (only relevant code shown): form.file_field :my_asset, direct_upload: true This will effectively put my asset in the root of my S3 bucket, upon submitting the form. How can I specify a prefix (e.g. "development/", so that I can mimic a folder on S3)? Sorry, that’s not currently possible. I’d suggest creating a bucket for Active Storage to use exclusively. My current workaround (at

DEPRECATION WARNING: Dangerous query method: Random Record in ActiveRecord >= 5.2

∥☆過路亽.° 提交于 2019-11-26 23:26:32
问题 So far, the "common" way to get a random record from the Database has been: # Postgress Model.order("RANDOM()").first # MySQL Model.order("RAND()").first But, when doing this in Rails 5.2, it shows the following Deprecation Warning: DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "RANDOM()". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as