ruby-on-rails-5.2

Separate secret_key_base in Rails 5.2?

核能气质少年 提交于 2020-01-01 08:04:13
问题 I just upgraded from 5.1 to 5.2 and I'm quite confused about this 'better' methodology to storing secrets... Maybe I'm not understanding, but it seems like now development and production have been 'merged' into a SINGLE SECRET_KEY_BASE as well as master.key ... is this correct? If not, how do I use a separate master key and SECRET_KEY_BASE in development? What if I have developers helping me and I don't want them to know my master key (or secrets) I use in production? 回答1: Rails 5.2 changed

ActiveStorage File Attachment Validation

时光怂恿深爱的人放手 提交于 2019-12-31 08:46:52
问题 Is there a way to validate attachments with ActiveStorage? For example, if I want to validate the content type or the file size? Something like Paperclip's approach would be great! validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/ validates_attachment_size :logo, less_than: 1.megabytes 回答1: Well, it ain't pretty, but this may be necessary until they bake in some validation: validate :logo_validation def logo_validation if logo.attached? if logo.blob.byte_size > 1000000

Rails 5.2 app, with angular as Front end not able to run on local to make a call for action cable

泄露秘密 提交于 2019-12-25 03:34:15
问题 I am running a rails 5 app(action cable), angular is also used in Front-end. Getting below error when angularJS tries to send request to rails server via /cable Started GET "/cable" for 127.0.0.1 at 2019-01-09 18:37:05 +0530 Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-01-09 18:37:05 +0530 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Exiting /home/testt/.rvm/gems/ruby-2.4.4@testt/gems/redis-3.3.5/lib/redis/connection

Rails: How to sum total price per day

╄→尐↘猪︶ㄣ 提交于 2019-12-25 01:49:58
问题 I want to calculate total price of ticket sales on the day it sold. But it shows total price of the last day (Today's total price). What i got now : October 20 Ticket 1 USD 1.11 Ticket 2 USD 2.22 Ticket 3 USD 3.33 Total For Today USD 7.77 (HERE'S THE PROBLEM) ------------------------------- October 21 Ticket 1 USD 1.11 Ticket 2 USD 2.22 Ticket 3 USD 4.44 Today's total USD 7.77 What i exactly want is : October 20 Ticket 1 USD 1.11 Ticket 2 USD 2.22 Ticket 3 USD 3.33 Today's total USD 6.66 ----

Rails 5 ActiveStorage How to wait for all threads to finish

与世无争的帅哥 提交于 2019-12-25 00:34:46
问题 First, let me describe the problem. I'm using RSpec to run a script to generate some test data. RAILS_ENV=development rspec spec/dev/food/food_upload.rb The script looks like this. image = fixture_file_upload(Rails.root.join('spec', 'resources', 'test2.png'), 'image/png') (0..200).each { food = FactoryBot.build :food p "Loading #{food.name}" expect { post :upload, params: { "foodUpload_foodName"=> food.name, "foodUpload_image"=> image } }.to change(Food, :count).by(1) .and change(Image,

DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s)

两盒软妹~` 提交于 2019-12-23 08:29:42
问题 I updated my rails 5.1.4 app to 5.2.0. I have the following scope in one of my models: scope :by_category, lambda { |category_slug| category_ids = Category.find_by(slug: category_slug)&.subtree_ids where(category_id: category_ids) } Rails returns me following error because of that scope: DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "coalesce(\"categories\".\"ancestry\", '')". Non-attribute arguments will be

Remove all data from Active Storage?

可紊 提交于 2019-12-19 07:58:58
问题 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 回答1: 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

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

Rail 5 swap ActionDispatch::Reloader with a custom reloader

懵懂的女人 提交于 2019-12-11 11:49:46
问题 We have a use case for mounting a mock engine to process sessions when developing locally in which a custom session middleware calls the mock engine via Net::http request when a request comes through. When there is code change, the reloader is triggered and here calls the ActiveSupport::Dependencies to start unloading. Then the request is pass down to our custom session middleware and the http request is fired. However since the http request calls to a mountable engine, it goes thought the

Loading a YML file in Rails, and maybe using a i18n file instead

血红的双手。 提交于 2019-12-11 09:32:05
问题 I have a dropdown.yml file that stores all my dropdown values for my multi-select fields in my forms. It is not environment dependent, so I do not have :development, :production, etc. I would like cache the file into a constant so I can use across my app. I found this command. config = Rails.application.config_for(:payment) However, it looks like it is environment dependent. What is the best way to add the yml? Second, should I use locales for this instead of a custom yml file? config