0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

email_fieldの入力フォームに初期値を反映させる方法

Posted at

#bootstrapを使用しながらemail_fieldの入力フォームに初期値を反映させる方法。
ポートフォリオを採用側に見てもらう時少しでも手間を省くため、ワンクリックで済むようにと初期値設定を考えました。
text_fieldは大量に検索ヒットしたけどemail_fieldとpassword_fieldは出てこなくて苦戦したので、自分用メモとして。

new.html.erb
        <%= form_with(url: login_path, scope: :session, local: true) do |f| %>

      <div class="form-group">
        <%= f.label :email, 'メールアドレス' %>
        <%= f.email_field :email, class: 'form-control', placeholder: 'hoge@gmail.com' %>
      </div>

      <div class="form-group">
        <%= f.label :password, 'パスワード' %>
        <%= f.password_field :password, class: 'form-control', value: 'hoge' %>
      </div>
      <%= f.submit 'ログイン', class: 'btn btn-primary btn-block' %>
    <% end %>

email_fieldの方には placeholder: 'hoge@gmail.com'
password_fieldの方には value: 'hoge'

下記のURLのchapter 7−4を参考にしてください。
email_fieldとpassword_field初期値設定

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?