![](/img/trans.png)
[英]Rails: Count the number of activerecord queries per route
我的主要想法是計算每 API 在 rails 中命中的 ActiveRecord 查詢的數量。 我正在研究 ActiveSupport 工具 API。它似乎已經提供了一些有用的數據。 view_runtime db_runtime 我還發現了一些可以計算查詢數量的寶石。 但是他們在日志數據中添加了查 ...
[英]Rails: Count the number of activerecord queries per route
我的主要想法是計算每 API 在 rails 中命中的 ActiveRecord 查詢的數量。 我正在研究 ActiveSupport 工具 API。它似乎已經提供了一些有用的數據。 view_runtime db_runtime 我還發現了一些可以計算查詢數量的寶石。 但是他們在日志數據中添加了查 ...
[英]In Rails are these Time difference command producing excepted bheviour? If so why?
重現步驟這是一種例外行為嗎? 打開導軌控制台。 鍵入以下命令:Time.zone.yesterday - Time.zone.now Output:Time.zone.now - Time.zone.yesterday Output:Time.zone.now - Time.zone.ye ...
[英]Hash deep transform all values if specific key
我對社區的尊重。 我有深層嵌套 hash 並且我想轉換提供的特定鍵的所有值。 deep transform values if key ==:something hash 的示例: 我想轉換所有鍵的所有值:status結果必須是: 我有幾個解決方案第一個: 第二個: 兩種解決方案都有效,但我不喜歡 ...
[英]How to expose ActiveSupport instrumentation metrics as HTTP response headers in Rails?
(78.3ms) ItemsController -- Completed #active -- { :view_runtime => 10.46, :db_runtime => 6.76, :controller => "ItemsController", :action =&g ...
[英]Why do i get "no_proxy = proxies.get('no_proxy') if proxies is not None else None AttributeError: 'str' object has no attribute 'get'"
我檢查了其他帖子,但他們似乎沒有解決這個問題。 這是我的代碼。 我得到的錯誤是: 我不確定這是否是一個愚蠢的錯誤,但我是 python 的新人所以請不要取笑我,如果可以的話請幫忙,我想從 proxies.txt 中選擇一個隨機代理並在每個請求中使用它。 所以請求1:111.68.31.155:80 ...
[英]Overriding an active support method with a ruby refinement
我想使用 Ruby Refinement 來修補 ActiveSupport 方法,以便以特定格式輸出時間。 我的最終目標是讓JSON.pretty_generate(active_record.as_json)以 UTC、iso8601、6 位小數打印所有時間戳。 我想讓所有其他時間戳打印正常運 ...
[英]In Ruby, how to add active_support/core_ext/time?
我發現一些 Ruby 代碼使用了:require "active_support/core_ext/time" require "active_support/core_ext/numeric" 在裝有 macOS Monterey 的 Mac 上,我還沒有 rails 或rvm ,如果我安裝r ...
[英]How does Ruby's ActiveSupport "between?" function handle impossible times?
我用的是ActiveSupport between? 確定時間是否在上午 8 點到下午 4:45 之間,我不小心將較晚的時間作為第一個參數,將較早的時間作為第二個參數,如下所示: 我知道這是錯誤的,因為我應該讓它使用16, 45而不是4, 45所以我能夠修復這個錯誤,但是我找不到關於這種情況下發生 ...
[英]Finding records where the current time is x pm in rails
我正在使用主動支持來查找 x pm 所在的時區。 然后查找該時區的記錄。 這些記錄中的時區是使用 Geocoder gem (Geocoder.search("ip_addr")) 設置的。 問題是 Geocoder 給出了一個類似“Asia/Thimphu”的時區值,但在 ActiveSuppor ...
[英]Use ActiveSupport Around-Callbacks to execute code (tracing/logging) around when my services are invoked?
在我的 app/services 目錄中,我有一堆服務,每個服務都有一個初始化方法和一個不采用 arguments 的公共perform方法。 顯示結構的簡單示例服務可能如下所示: 我的目標是向我的應用程序添加跟蹤,以便我可以跟蹤我的每個服務何時被調用,而無需顯着修改每個服務的代碼。 最后,我希望 ...
[英]Upgrading to Ruby 3.1 causes Psych::DisallowedClass exception when using YAML.load_file
升級到 ruby 3.1 時,我在使用YAML.load_file some_file_name時看到以下排序錯誤消息 其他加載語句會導致類似的錯誤,但引用了不同的未指定類,例如 OpenStruct。 似乎最新版本的 YAML 僅從允許的白名單中加載類,因此需要使用 allowed_cla ...
[英]undefined method `mechanism=' for ActiveSupport::Dependencies:Module (NoMethodError)
我在 rails 7.0.0 中生成 controller 時遇到問題當我運行命令時 它給了我以下錯誤。 我用谷歌搜索但沒有找到解決方案。 那么這個錯誤的原因是什么? ...
[英]WashOut::Soap parameters missing when upgrading to Rails 6 actionpack 6
我在我的 Ruby Rails controller 中使用了 Washout::SOAP ,它具有這樣的soap_action: 在我的規格測試中,我有: 這在我使用 Rails 5 和 actionpack 5 時有效。但是,當我切換到 Rails 6 和 actionpack 6 時,para ...
[英]A similar method like presence but considers false to be present
剛剛意識到在false boolean 上調用.presence返回nil而不是false 。 有沒有類似的東西基本上認為是false的? 例如: 就我而言,我有一些設置為false的數據庫屬性,但它們實際上是有效值,因此返回nil可能會有點混亂。 例如: 如果有這樣的東西會很好: 我的一個模型中有 ...
[英]Rails active_support uninitialized constant I18n (NameError)
我正在運行帶有 Ruby 2.6.5 的 Rails 5.2.3。 沒有明顯的原因,突然之間我收到了與帶有 active_support 的 I18n 相關的錯誤。 我沒有做國際化的願望,並且會很滿足,沒有任何痕跡。 我知道這在一定程度上是內置的,但不明白為什么突然出現以下錯誤。 我所做的最新操作 ...
[英]How to add raw_filter method to ruby on rails 7?
在 rails 7 中,我使用 gem 'activerecord-import' 將數據導入我的數據庫並避免多次插入,例如: 當我運行代碼時: 我收到以下錯誤: 發生該錯誤是因為 Rails 7 從 ActiveSupport::Callbacks::Callback 中刪除了 raw ...
[英]Add 30 seonds to minutes in time class in Ruby
我在 Ruby 中使用了以下格式,效果很好。 ...
[英]Why Rails6+ started adding activesupport requires in config/environments/* by default?
我對 Rails 版本升級有點晚了。 令我驚訝的是 Rails 生成的 config/environment/* 文件中有一堆 active_support 要求。 它們是干什么用的? 它與 Rails6 中引入的 Zeitwerk 有關嗎? 我不記得它們出現在舊版本的 Rails 中。ag ^r ...
[英]How to handle timezones in Rails when using fixed time ranges
我覺得我要在這個房子周圍轉一圈。 總之,我有一個位置 model ,它有開放時間,在數據庫中建模為opens_at和closes_at 。 所有時間都以 UTC 格式存儲在數據庫中。 如果我在紐約創建一個位置,並在我的表單中設置為 08:30 的opens_at並將它作為 08:30 UTC 保存到 ...
[英]Sidekiq -r a single demo_worker.rb file, and require active support in that worker doesnt work
我想在我的 demo_worker.rb 中要求 active_support。 然后我跑了sidekiq -r./demo_worker.rb 它告訴我不能需要active_support,我也嘗試需要rails,但仍然沒有工作。 如何在 sidekiq 的普通模式下需要 active_suppo ...