2
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 5 years have passed since last update.

deviseでユーザー認証をしよう

Last updated at Posted at 2019-09-02

#deviseでカラムを追加して、ログイン機能を実装するには・・・

##userモデルを作成するところまではこちら
https://qiita.com/mokku/private/aa4191817369edb269fb
最低限のログインページ実装は上で完了しています。

##deviseのビューを生成する

$ rails g devise:views
Running via Spring preloader in process 5927
      invoke  Devise::Generators::SharedViewsGenerator
      create    app/views/devise/shared
      create    app/views/devise/shared/_error_messages.html.erb
      create    app/views/devise/shared/_links.html.erb
      invoke  form_for
      create    app/views/devise/confirmations
      create    app/views/devise/confirmations/new.html.erb
      create    app/views/devise/passwords
      create    app/views/devise/passwords/edit.html.erb
      create    app/views/devise/passwords/new.html.erb
      create    app/views/devise/registrations
      create    app/views/devise/registrations/edit.html.erb
      create    app/views/devise/registrations/new.html.erb
      create    app/views/devise/sessions
      create    app/views/devise/sessions/new.html.erb
      create    app/views/devise/unlocks
      create    app/views/devise/unlocks/new.html.erb
      invoke  erb
      create    app/views/devise/mailer
      create    app/views/devise/mailer/confirmation_instructions.html.erb
      create    app/views/devise/mailer/email_changed.html.erb
      create    app/views/devise/mailer/password_change.html.erb
      create    app/views/devise/mailer/reset_password_instructions.html.erb
      create    app/views/devise/mailer/unlock_instructions.html.erb

##ビューファイルの編集を行う
今回は、追加でニックネームを入力してもらいたいのでニックネームの入力欄を追加します。
※一旦、仮で反映させておきます。

new.html.erb
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>

  <div class="field">
    <%= f.label :nickname %><br />
    <%= f.text_field :nickname, autofocus: true, autocomplete: "email" %>
  </div>

image.png

ニックネーム入力欄ができました。

##コントローラを作成しよう

ターミナルで下記コマンドを入力してコントローラを作成する

$ rails g controller [コントローラ名]
$ rails g controller users

image.png

##参考
deviseのビューファイル
https://qiita.com/yasuno0327/items/ff17ddb6a4167fc6b471

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