Ruby on Rails Cheatsheet
Architecture
Create a new application
Install the Rails gem if you haven't done so before
require 'rails_helper' | |
RSpec.describe TodosController, :type => :controller do | |
describe "GET #index" do | |
#describe "POST #create" do | |
#describe "GET #show" do | |
#describe "PATCH #update" do (or PUT #update) | |
#describe "DELETE #destroy" do | |
#describe "GET #new" do |
# This is a skeleton for testing models including examples of validations, callbacks, | |
# scopes, instance & class methods, associations, and more. | |
# Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
# | |
# I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
# so if you have any, please share! | |
# | |
# @kyletcarlson | |
# | |
# This skeleton also assumes you're using the following gems: |
# Adapted from https://tinyapps.org/blog/nix/201701240700_convert_asciidoc_to_markdown.html | |
# Using asciidoctor 1.5.6.1 and pandoc 2.0.0.1 | |
# Install pandoc and asciidoctor | |
sudo apt install asciidoctor | |
sudo wget https://github.com/jgm/pandoc/releases/download/2.0.0.1/pandoc-2.0.0.1-1-amd64.deb | |
sudo dpkg -i pandoc-2.0.0.1-1-amd64.deb | |
# Convert asciidoc to docbook using asciidoctor |
If the following error occurs even though libc6-dev is installed,
Do you install glibc-devel(redhat) or libc6-dev(debian)?
You need /usr/include/sys/types.h to compile ruby-oci8.
You need to use ruby-oci8 2.1.0 or upper. Otherwise, run the following command and re-install ruby-oci8.
SELECT '2018-07-1', WEEKOFMONTH('2018-07-1') AS week_of_month; | |
SELECT '2018-07-5', WEEKOFMONTH('2018-07-5') AS week_of_month; | |
SELECT '2018-07-7', WEEKOFMONTH('2018-07-7') AS week_of_month; | |
SELECT '2018-07-8', WEEKOFMONTH('2018-07-8') AS week_of_month; | |
SELECT '2018-07-10', WEEKOFMONTH('2018-07-10') AS week_of_month; | |
SELECT '2018-07-14', WEEKOFMONTH('2018-07-14') AS week_of_month; | |
SELECT '2018-07-15', WEEKOFMONTH('2018-07-15') AS week_of_month; | |
SELECT '2018-07-20', WEEKOFMONTH('2018-07-20') AS week_of_month; |
class User < ActiveRecord::Base
store :settings, accessors: [ :color, :homepage ], coder: JSON
end
u = User.new(color: 'black', homepage: '37signals.com')
u.color # Accessor stored attribute
u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
# There is no difference between strings and symbols for accessing custom attributes
# encoding | |
class ModelName < ApplicationRecord | |
# require statements | |
# extend Modules | |
# include Modules | |
# Gem/Plugins options | |
# CONSTANTS | |
# Attribute accessors | |
# serialize attributes |
## API | |
* http://apionrails.icalialabs.com/book/chapter_one | |
* https://medium.com/statuscode/introducing-webpacker-7136d66cddfb#.9aou0hodw | |
* https://blog.codeship.com/building-a-json-api-with-rails-5/ | |
* http://blog.arkency.com/2016/02/how-and-why-should-you-use-json-api-in-your-rails-api/ | |
* https://github.com/tiagopog/jsonapi-utils | |
* https://robots.thoughtbot.com/validating-json-schemas-with-an-rspec-matcher | |
* https://github.com/interagent/heroics | |
* http://weblog.rubyonrails.org/2017/2/23/Rails-5-1-beta1/ | |
* http://blog.michelada.io/whats-new-in-rails-51 |