LoginSignup
1
5

More than 3 years have passed since last update.

本日の学習まとめ ユーザー管理機能実装にて

Posted at

はじめに

 今回は完全に自分用で覚えておきたいことを雑多に書き連ねている。

正規表現

 


PASSWORD_REGEX = /\A(?=.*?[A-z])(?=.*?[\d])[A-z\d]+\z/i.freeze # 半角英数混合1字以上
ZENKAKU_REGEX = /\A[ぁ-んァ-ン一-龥]+\z/.freeze # 全角ひらカタ漢字
KANA_REGEX = /\A[ァ-ヶー-]+\z/.freeze # 全角カナ

freezeは変数が変わらないようにするため。

バリデーションのオプションをまとめる


with_options presence: true do
 validates #オプションをつける 
end

エラーメッセージを表示させる

foem_withの中でrenderメソッドでファイルを呼び出す。そのとき、devise配下のファイルであるように記述をする。


<%= form_with model: @user, url: user_registration_path', local: true do |f| %>
  <%= render 'devise/shared/error_messages', model: f.object %>
_error_messages.html.erb
<% if model.errors.any? %>
  <div id="error_explanation">
    <h2>
      <%= I18n.t("errors.messages.not_saved",
                 count: model.errors.count,
                 resource: model.class.model_name.human.downcase)
       %>
    </h2>
    <ul>
      <%= model.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
    </ul>
  </div>
<% end %>

modelを呼び出すように記述する。
1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5