This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bad | |
params[:search_type].present? && params[:search_type] == 'Dashboard' | |
# good | |
params[:search_type] == 'Dashboard' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sample_hash = { a: 1, b: 10 } | |
# bad | |
sample_hash.merge!({ c: 20, d: 30 }) | |
# good | |
sample_hash.merge!(c: 20, d: 30) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bad | |
properties.present? && properties[:user].present? && properties[:user][:profile].present? | |
# Better approach | |
properties.try(:[], :user).try(:[], :profile).present? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
employee_city_data = { Bob: 'Banglore', Steve: 'Pune', Joe: 'Ahmedabad' } | |
# bad | |
employee_city_data[:Naiya] || 'Ahmedabad' | |
# good | |
employee_city_data.fetch(:Naiya, 'Ahmedabad') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpack = require('webpack') | |
environment.plugins.prepend('Provide', | |
new webpack.ProvidePlugin({ | |
$: 'jquery/src/jquery', | |
jQuery: 'jquery/src/jquery' | |
}) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("@rails/ujs").start() | |
require("turbolinks").start() | |
require("@rails/activestorage").start() | |
require("channels") | |
require("jquery") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatePosts < ActiveRecord::Migration[6.0] | |
def change | |
create_table :posts do |t| | |
t.string :title, index: { unique: true } | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ApplicationRecord | |
validates :title, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.pluck(:id, :name) | |
# SELECT users.id, users.name FROM users | |
# => [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.limit(1).pluck(:name).first | |
# SELECT "users"."name" FROM "users" LIMIT ? [["LIMIT", 1]] | |
# => "David" | |
User.where(id: 1).pluck(:name).first | |
# SELECT "users"."name" FROM "users" WHERE "users"."id" = $1 | |
# => "David" |