Other topics
Adding a JSON Column to a table
The following adds a column named client_data
to a table named Bills
. Notice that the singular form "Bill" is used when creating the migration although the table's name is "Bills."
bash
rails g migration AddClientDataToBill client_data:json
ruby
class AddClientDataToBill < ActiveRecord:Migration[6.1]
def change
add_column :bill, client_data, :json
end
end
Scopes
Partials
Helpers
Services
Mailers
Sending emails
lib
Channel
Jobs
Vendor
Factory
Spec
Gems
db
Useful Methods
.dig()
ruby
obj = { foo: {bar: {baz: 1}}}
obj.dig(:foo, :bar, :baz) #=> 1
Get method parameters
ruby
def foo(a,b)
puts "Hello"
end
metho = method(:foo)
metho.parameters
Get unique method for class
ruby
Class.methods - ActiveRecord::Base.methods
Class.methods - Object.methods
Kill a server process
bash
lsof -wni tcp:3000
kill -9 51195