Skip to content

Instantly share code, notes, and snippets.

let

using variable first, and define can be later.

subject { AddressDeserializer.new(hash: report_params) }
describe "valid params" do
   let(:report_params) { { reference: "97801c47-c362-41eb-919e-036514fca39c" } }
end  
@JamesYang76
JamesYang76 / Time Zone.md
Last active August 29, 2024 09:22
Time Zone for rails

Time zones

There are trhee diffrent time zones in rails

  • System - The server time zone
  • Application - Rails application use own time zone
  • Database - Default is UTC, but do not change it

Cautions

  • config.time_zone should be set when an app dose not support multiple time zones
  • Do not use Date/Time API using system time zone
  • Date could be incorrect by being converted from datetime or time to date

Workflow advice

When upgrading Rails versions(major or minor), we can encounter lots of unique issues.
I am writing some generic advice on how you want to tackle the update in principle.

  • Do a separate step for each major rails versions. For instance, Rails 3 to 5, there can be two steps: 3.x -> 4.2 -> 5.2
  • Do not bundle update, which can cause serious problems. Please, only update gems which have dependency errors of rails.

When we update patch(0.0.x)level, it is enough just only to update rails gem.\

change mode

$ rails s -e production
or 
$ RAILS_ENV=production rails s
or
$ export RAILS_ENV=production
$ printevn | grep RAILS_ENV
$ rails s

Webpacker

init

Change folder name from app/javascript to app/webpack

# config/webpack/webpacker.yml
# change source_path from app/javascript to app/webpack
source_path: app/webpack

Make folder named stylesheets and add application.scss into the folder\

@JamesYang76
JamesYang76 / basic.md
Created October 11, 2019 04:28
Linux basic

create ssh

$ ssh-keygen -f mykey
.blog-grid {
  @include xy-grid;
}

.blog-item {
  @include xy-cell(4,false,0);
}

Block

def print_once
  yield
end

print_once { puts "Block is being run" }

def my_block
  yield 2
@JamesYang76
JamesYang76 / active_record.md
Last active April 16, 2020 02:21
ActiveRecord

supported type

:binary
:boolean
:date
:datetime
:decimal
:float
:integer
@JamesYang76
JamesYang76 / aws general.md
Last active December 28, 2020 12:45
AWS general

CLI config

# make default profile
$ aws configure
$ aws configure --profile user1

$ cat ~/.aws/credentials
[default]
aws_access_key_id = AWS_KEY_ID