gem 'annotate'

gem 'annotate' を使用すると、 modelにテーブルの情報を自動で書き出してくれる。 Gemfileに記入後、bundle installし、 bundle exec annotate と、コマンドを打つだけで完了。

deviseでUserのパスワード変更

Deviseを使用し、Userのパスワードを変更しようと、 user.updateをかけると、 ログアウトしてしまう。 そのため、 ログアウト後に、もう一度ログインさせるため、 redirect_toの前に、以下のコードを書く。 sign_in(@user, bypass: true) if current_user.id…

active_hash

gem 'active_hash' gemのactive_hashを使用すると、静的なデータ用のモデルが作成できる。 app/models/user.rbを作成し、以下のように記述する。 class User < ActiveHash::Base self.data = [ { id: 1, name: "a" }, { id: 2, name: "b" } ] end すると、 U…

Capistrano config/deploy/production.rb

config/deploy/production.rbのroleについて サーバーが一台の場合 server 'hostname', user: 'username', roles: %w{app db web} set :ssh_options, { port: 'ssh-port', keys: File.expand_path('key-path'), } でよいが、 サーバーが複数の場合は、 role …

gem 'data-confirm-modal'

link_to "", ~_path, data: { confirm: ~ } としたときに、表示されるモーダルウィンドウのスタイルを変更するには、 data-confirm-modal が便利。 bundle install後、 //= requiredata-confirm-modal をapplication.jsに追記。(あるいは、github上のdata-c…