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 == @user.id
これで、ログインしたままの状態でパスワードのupdateが可能。
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
すると、
User.find(1)
User.all
などが使える。
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 :app, %w{ username@hostname }
role :web, %w{ username@hostname }
role :db, %w{ username@hostname }
set :ssh_options, {
port: 'ssh-port',
keys: File.expand_path('key-path'),
}
として対応する。
gem 'data-confirm-modal'
link_to "", ~_path, data: { confirm: ~ }
としたときに、表示されるモーダルウィンドウのスタイルを変更するには、
data-confirm-modal
が便利。
bundle install後、
//= requiredata-confirm-modal
をapplication.jsに追記。(あるいは、github上のdata-confirm-modal.jsそのままの.jsファイルを作成する)
これにより、
link_to "", ~_path, data: { confirm: ~ , commit: ~, cancel: ~}, title: ~
とすると、
各モダール部分の記載事項を変更することができる。
参考url: