Skip to content

Instantly share code, notes, and snippets.

@TakuyaHarayama
TakuyaHarayama / .rubocop.yml
Created September 14, 2017 02:45
Railsのrubocopサンプル
# Railsのチェックを有効にする
Rails:
Enabled: true
# 日本語でのコメントを許可
AsciiComments:
Enabled: false
# モジュール名::クラス名の定義を許可
ClassAndModuleChildren:
@TakuyaHarayama
TakuyaHarayama / .sass-lint.yml
Created September 14, 2017 02:42
Railsのsass解析サンプル
#########################
## Sample Sass Lint File
#########################
# Linter Options
options:
# Don't merge default rules
merge-default-rules: false
# Set the formatter to 'html'
formatter: html
# Output file instead of logging results
https://trix-editor.org/
シンプルで使いやすい
アップデートが多い
https://jhollingworth.github.io/bootstrap-wysihtml5/
bootstrap製
http://neilj.github.io/Squire/
@TakuyaHarayama
TakuyaHarayama / gist:c31a3e0e17e5b0ecdfd60b0402ead80f
Last active June 7, 2017 16:16
前のページに戻るアクション
class ApplicationController < ActionController::Base
before_action :set_request_from
# どこのページからリクエストが来たか保存しておく
def set_request_from
if session[:request_from]
@request_from = session[:request_from]
end
# 現在のURLを保存しておく
session[:request_from] = request.original_url
@TakuyaHarayama
TakuyaHarayama / gist:264b8ea9e751424ba4150999ab8405cb
Last active June 7, 2017 16:17
カレントディレクトリ配下のファイル数カウント
find ./ -type f | wc -l
bin/rails erd attributes=foreign_keys,primary_keys,content filename=erd filetype=png
@TakuyaHarayama
TakuyaHarayama / gist:09ed4e5a7ac92db0de4d05b32b250a5e
Last active June 7, 2017 16:18
ユーザーと映画とユーザーのお気に入り映画があって、特定のユーザーのお気に入りの映画と邦画を合わせて取得するscope
scope :search_with_japanese_favorite_movie, -> (user_id) {
eager_load(:user_favorite_movies)
.merge( UserFavoriteMovie.where(user_id: user_id) )
.or( Movie.eager_load(:user_favorite_movies).where(made_in: "Japan") )
}
@TakuyaHarayama
TakuyaHarayama / Polymorphic URLサンプル
Last active June 7, 2017 16:15
namespace使ったりmodule使ったり特定のアクションを指定するリンク生成
= link_to [:edit, :admin, :hoge, @user, @item]
# /admin/hoge/users/@user.id/items/@item.id/edit