Tips
Rails tips
- 📚 Ruby on Rails API
- 📚 Rails Guide
- 💡 force stop rails server
-
kill -9 $(cat tmp/pids/server.pid)
-
Ruby tips
Convert to Hash from a couple of the key-value Array in Rails
n350071🇯🇵 ・ Sep 30 '19 ・ 1 min read
Design/Architecter Pattern
Concern | split, and spin-off, share the responsibility in Rails
n350071🇯🇵 ・ Sep 27 '19 ・ 1 min read
- decorator
Gems
Overwrite a gem method by inserting a module in your inheritance chain
n350071🇯🇵 ・ Nov 27 '19 ・ 1 min read
Authorization
organize the authorizations of the banken/pundit gem with define_method
n350071🇯🇵 ・ Sep 25 '19 ・ 1 min read
State machines, Status
- aasm
Code Quarity
static security analysis for Rails app by using Breakman
n350071🇯🇵 ・ Sep 25 '19 ・ 1 min read
Rails Standard Features
- secrets, credentials
Model
Making a nested params for xxx_tag of View Helper in Rails
n350071🇯🇵 ・ Sep 30 '19 ・ 1 min read
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)
Ping controller for the Server Monitoring(死活監視)
class PingController < ApplicationController
def index
render text: 'OK', layout false
end
end
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
Routes
pass a model with some params
# The request is `article/:id?author=n350071`
article_path(@article, author: 'n350071')
I18n
DB
rake
Meta Programing
Append a method to all attributes with attribute_method_suffix in Rails
n350071🇯🇵 ・ Sep 25 '19 ・ 1 min read
mattr_accessor and meta programming. Thanks you, devise_invitable 👍
n350071🇯🇵 ・ Nov 7 '19 ・ 1 min read
the eval meta programming power. Making .env file and Set Constant values from the file
n350071🇯🇵 ・ Nov 7 '19 ・ 1 min read
Debug
Dive into Gem file
1. set your favorit editor
# bash_profile
export EDITOR="/Applications/Atom.app/Contents/MacOS/Atom"
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
Setting / Config
rails-starter-kit-with-docker
You can create a rails app on docker with only 3 commands.
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)