Tips to make your code shorter and cleaner

Fetch params in controller

# Instead of
def important_field
  params[:important_field] || :default_value
end

# Use
def important_field
  params.fetch(:important_field, :default_value)
end
sort_options = [:by_date, :by_title, :by_author]

# Instead of
sort_by = sort_options.include?(params[:sort]) ? params[:sort] : :by_date

# Use
sort_by = params[:sort].presence_in(sort_options) || :by_date

Try to deep access a hash

hash = { user: { profile: { name: 'Kevin' } } }

# Instead of
hash.try(:[], :user).try(:[], :profile).try(:[], :name)

# Use
hash.dig(:user, :profile, :name)