DEV Community

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

Posted on โ€ข Edited on

3

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โ€ฆ

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how theyโ€™re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free โ†’