Rails
Railsのパーシャル内で現在のインデックス数を取得する方法です。 パーシャル内で #{variable_name}_counter で取得可能です。 = render partial: 'users/user', collection: @users index : <%= user_counter %>
Rspec実行時に以下で怒られました。 WARNING: Using `expect { }.not_to raise_error(SpecificErrorClass)` risks false positives, since literally any other error would cause the expectation to pass, including those raised by Ruby (e.g. `NoMethod…
rails active_storage:install をしようとしたら以下のエラー Don't know how to build task 'active_storage:install' config/application.rb で以下をコメントアウトしているのが原因でした # require "active_storage/engine"
Railsプロジェクトを動かそうとしたら下記のエラー Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of mimemagi…
環境 Ruby 2.7.2 Rails 6.1.0 最小限の rails new rails new --minimal -S -J -T --database=postgresql TestApp --minimal 以下のフレームワークがスキップされる action_cable action_mailbox action_mailer action_text active_job active_storage bootsn…
RailsアプリでSearchkickを使いElasticsearchのreindexをしようとしたところデータ量が大きすぎるとのエラー Elasticsearch::Transport::Transport::ServerError · [429] {"error":{"root_cause":[{"type":"circuit_breaking_exception","reason":"[parent] …
例えば created_on に日付が入っているこんなデータ Post.last Post Load (13.1ms) SELECT "posts".* FROM "posts" => #<Post id: 1, user_id: 1, created_on: "2020-11-02"> pluck を使うだけだと同じ日付が入ってしまう Post.pluck(:created_on) (2.7ms) SELECT "posts"."created_on" FROM "posts" => [Mon, 0</post>…
RAILS_ENV で test を指定する bundle exec rails db:migrate:reset RAILS_ENV=test 削除、作成、migrateを個別にする bundle exec rails db:drop RAILS_ENV=test bundle exec rails db:create RAILS_ENV=test bundle exec rails db:migrate RAILS_ENV=test
Rubyの簡単なサンプル arr = [ { name: "hoge1", age: 10 }, { name: "hoge2", age: 13 }, { name: "hoge3", age: 15 }, { name: "hoge4", age: nil } ] arr.min_by{ |e| e[:age] } => ArgumentError (comparison of NilClass with 10 failed) ブロックの戻…
以下の設定の場合 class User < ActiveRecord::Base enum role: { admin: 1, viewer: 2, other: 3 } ... Rails5の場合 user = User.create(role: 1) user.role_before_type_cast # => 1 # もしくは user.class.roles[user.role] # => 1 Rails4以前は user = …
解決法 とりあえず解決した方法。 無いぞと言われてるパスにシンボリックリンクを張る ln -s /usr/local/opt/readline/lib/libreadline.dylib /usr/local/opt/readline/lib/libreadline.6.dylib 出たエラー /Users/user/.rbenv/versions/2.4.0/lib/ruby/2.4.…
Ransackのconditionには入れられないらしい NULLS LASTでsortするには Ransackの外側で普通にOrder指定する Model.search(conditions).result.order('column DESC NULLS LAST') 脱Ransackしたい 参考 How to add NULL LAST to sorts · Issue #443 · activere…
タイトルママ nulls lastのインデックスを作りたいけどなかなか見つからなかったので書きました。 migration にこれ add_index :table, :column, order: { column: 'DESC NULLS LAST' } 参考 PostgreSQL: Ordering, NULLs, and indexes - makandropedia 元の…
<br /> を出力したくて content_tag(:br) とやったら <br></br> と出力されてしまった… content_tagじゃなくてtagを使うとのこと なるほどcontentがあるかないかの単純な話だったらしい tag知らなかった… 結果 無事brタグが出力されました tag(:br) ↓ <br />