DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

n350071๐Ÿ‡ฏ๐Ÿ‡ต
n350071๐Ÿ‡ฏ๐Ÿ‡ต

Posted on • Updated on

My Rails note

Tips

Rails tips

Ruby tips










Design/Architecter Pattern




Gems

Authorization


State machines, Status

  • aasm

Code Quarity



Rails Standard Features

  • secrets, credentials

Model





View & Helper


Form



Controller

where the request comes from?

# confirm the request comes from `new_book_path`
request.referer.to_s.index(new_book_path)
Enter fullscreen mode Exit fullscreen mode

Ping controller for the Server Monitoring(ๆญปๆดป็›ฃ่ฆ–)

class PingController < ApplicationController
  def index
    render text: 'OK', layout false
  end
end
Enter fullscreen mode Exit fullscreen mode

iframe Same Origin Policy

class HogeController < ApplicationController
  after_action :allow_iframe_for_trusted_domain, only[:index]

  private
  # Turn enable to see a page in a specific domain by using this method.
  # Because of the Same-Origin-Policy, it can't do it by default.
  def allow_iframe_for_trusted_domain
    alllow_url = "https://n350071.com"
    response.headers['X-Frame-Options'] = "ALLOW-FROM #{alllow_url}"
    response.headers['Content-Security-Policy'] = "frame-ancestors #{alllow_url}" # Chrome็”จ
  end  
end
Enter fullscreen mode Exit fullscreen mode

Routes

pass a model with some params

# The request is `article/:id?author=n350071`
article_path(@article, author: 'n350071')
Enter fullscreen mode Exit fullscreen mode

I18n

DB

rake

Meta Programing




Debug

Dive into Gem file

1. set your favorit editor

# bash_profile
export EDITOR="/Applications/Atom.app/Contents/MacOS/Atom"
Enter fullscreen mode Exit fullscreen mode

Don't forget to . ~/.bash_profile after updating.

2. open the bundled gem

just do it like this.

bundle open faker
bundle open banken
bundle open aasm
Enter fullscreen mode Exit fullscreen mode

Setting / Config

rails-starter-kit-with-docker

You can create a rails app on docker with only 3 commands.

Screenshot

screenshot

Usage

Assumptions

I suppose that you already have docker machine If you don't have it, please install it.

And also, you're at the project root directory like new-app If you haven't been yet, type following commands.

mkdir new-app
cd new-app/

1. Clone this repository to your new app directory

git clone git@github.com:n350071/rails-starter-kit-with-docker.git

2. Copy build files

sh rails-starter-kit-with-docker/cp_build_file.sh

You can rename the app name from myapp with replace command There is a CAPITAL MYAPP, so take care of it.

3. Initialize your new project

make init-project

It starts rails and you can check it by http://localhost:3000. when you want to stop your docker, please type

make stop

Option

You can off the comment at # - ./vendor/bundle:/usr/local/bundle in docker-compose.yml So you can saveโ€ฆ

Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git