LoginSignup
5
4

More than 5 years have passed since last update.

railsでコード書いてる時に思い出す用のメモ

Last updated at Posted at 2018-04-25

rails書いててあーなんだっけってよくググったり、レビューしててこんな感じでってリンクをコピペする時に使う自分用のメモ

user.role_before_type_cast
> 1

[User.roles[:general], User.roles[:special]].exclude?(@user.role_before_type_cast)

  • sortしたい場合
k.sort { | a, b | a.updated_at <=> b.updated_at } 

# 指定したid順にsortしたいとき
key = ['333','1000','1','11']
k = Keyword.where(id: [333,1000,1,11]) 
k = Keyword.where(id: key).order(['field(id, ?)', key]) # 333,1000,1,11の順番で出力したい
  • specでchangeをつなげるとき
+      it do
+        expect { subject }.to change { User.all.size }.from(1).to(0)
+                         .and change { UserProfile.all.size }.from(1).to(0)
+      end
  • modelの差分を取り出す時
Model.previous_changes
(Model.change?だとsaveが走ったらもう取れない)

開発してる時にあったらいいgem

🍣  cat config/initializers/rails_footnotes.rb
defined?(Footnotes) && Footnotes.setup do |f|
  f.enabled = Rails.env.development?
  f.lock_top_right = true
end

ちょいちょい見るスライド

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4