0
0

view/devise/passwords/edit.html.erbとview/users/edit.html.erbの違い

Posted at

①app/view/devise/passwords/edit.html.erb

目的

このファイルは、パスワードをリセットするためのビューを提供するためのもの。
ユーザーが「パスワードを忘れた」場合に、メールで送信されたリンクを使って新しいパスワードを設定するためのフォームとなる。

主な機能

・パスワードリセットトークンの入力
・新しいパスワードの入力
・パスワードの確認
・フォームの例

実装例

app/view/devise/passwords/edit.html.erb

<h2>Change your password</h2>

<%= form_with(model: resource, url: password_path(resource_name), method: :put, local: true) do |f| %>
  <%= devise_error_messages! %>

  <div class="field">
    <%= f.label :password, "New password" %>
    <%= f.password_field :password, autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation, "Confirm new password" %>
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
  </div>

  <div class="actions">
    <%= f.submit "Change my password" %>
  </div>
<% end %>

②app/views/users/edit.html.erb

目的

このファイルは、ユーザーが自分のプロフィール情報(例:ニックネーム、メールアドレス、パスワードなど)を編集するためのビューを提供します。

主な機能

・ニックネームの編集
・メールアドレスの編集
・パスワードの変更
・パスワード確認
・現在のパスワードの入力(変更確認用)
・フォームの例

実装例

app/views/users/edit.html.erb
<h2>ユーザー情報編集</h2>

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
        <% @user.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :nickname %>
    <%= f.text_field :nickname %>
  </div>

  <div class="field">
    <%= f.label :email %>
    <%= f.email_field :email %>
  </div>

  <div class="field">
    <%= f.label :password %> <i>(変更しない場合は空欄のまま)</i>
    <%= f.password_field :password, autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation %>
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :current_password %> <i>(確認のため現在のパスワードを入力してください)</i>
    <%= f.password_field :current_password, autocomplete: "off" %>
  </div>

  <div class="actions">
    <%= f.submit "更新" %>
  </div>
<% end %>

違いのまとめ

目的

devise/passwords/edit.html.erbはパスワードリセット用、users/edit.html.erbはユーザー情報の編集用です。

機能

devise/passwords/edit.html.erbは新しいパスワードの設定、users/edit.html.erbはユーザーのプロファイル全般の編集を行います。

フォームの内容

devise/passwords/edit.html.erbはパスワードリセットに必要なフィールドのみを持ちますが、users/edit.html.erbはニックネーム、メールアドレス、パスワード、現在のパスワードなどのフィールドを持ちます。
それぞれのファイルは、、その目的に応じたフォームを提供し、ユーザーが必要な操作を行えるように設計されています。

0
0
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
0
0