View implicit_order_column.rb
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 Claim < ActiveRecord::Base | |
self.implicit_order_column = :created_at | |
end |
View feed.rb
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 Feed < ActiveRecord::Base | |
enum status: %i[ active pending trashed ] | |
end | |
Feed.not_active # => where.not(status: :active) | |
Feed.not_pending # => where.not(status: :pending) | |
Feed.not_trashed # => where.not(status: :trashed) |
View rails6_pick.rb
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.pick(:name) | |
# SELECT "users"."name" FROM "users" LIMIT ? [["LIMIT", 1]] | |
# => "David" | |
User.where(id: 5).pick(:name, :city) | |
# SELECT "users"."name", "users"."city" FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]] | |
# => ["Naiya", "Goa"] |
View before_rails6.rb
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" |
View pluck.rb
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']] |
View post.rb
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 |
View create_posts.rb
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 |
View application.js
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") |
View code_in_environment.js
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' | |
}) | |
) |
View hash_fetch.rb
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') |
NewerOlder