Rails Tips & Tricks #1



1. Hash#dig

... if params[:user] && params[:user][:address] && params[:user][:address][:somewhere_deep]

can be
... if params.dig(:user, :address, :somewhere_deep)

2. Object#presence_in

sort = sort_options.include?(params[:sort]) ? params[:sort] : :by_date

can be

params[:sort].presence_in(sort_options) || :by_date


https://hackernoon.com/

Comments