LoginSignup
0
0

More than 3 years have passed since last update.

Rails 自作アプリへの道 Part2

Posted at

Rails 自作アプリを作った時の経過をまとめていきます。

環境

OS Ruby Rails
Mac Mojave 10.14.16 2.6.3p62 5.0.7.2

参考
https://qiita.com/cigalecigales/items/f4274088f20832252374

前提
環境構築済

【conformableの設定】

1.送信メールアドレスの登録

①設定ファイルの追記/編集

config/environments/depelopment.rb
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :user_name => "Gメールアドレス", # メアドを書く
    :password => "Gメールパスワード",
    :authentication => :plain,
    :enable_starttls_auto => true
  }
config/initialiezers/devise.rb

  config.mailer_sender = 'Gメールアドレス' # メアドを書く

②gmailアプリパスワードの取得、追記

config/environments/development.rb

   (省略)
    :password => "Gメールパスワード", # Gmailのアプリパスワードを書く
   (省略)

③サインアップ、ログインの検証

サーバーを起動し、サインアップ。
確認メールをMacで開き、『Confirm my accout』をクリック
その後、ログイン可能か確認する

【lockableの設定】

1.設定値の登録

①設定ファイルの編集 ※ 必要に応じて、設定値やコメントの有無を変更

config/initializers/devise.rb

   (省略)

  config.lock_strategy = :failed_attempts

  config.unlock_keys = [:email]

  config.unlock_strategy = :both

  config.maximum_attempts = 20

  config.unlock_in = 1.hour

  config.last_attempt_warning = true

   (省略)

【timetableの設定】

1.設定値の登録

①設定ファイルの編集 ※ 必要に応じて、設定値やコメントの有無を変更

config/initializers/devise.rb

   (省略)

  # config.timeout_in = 30.minutes


   (省略)

【その他の設定】

1.サインアップ画面で入力させたい項目の追加

①設定ファイルの編集 ※ 必要に応じて、入力させたい項目を追加

app/views/devise/registrations/new.html.erb

<h2>サインアップ</h2>

<%= 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 :sellername, '取扱者' %><br />
    <%= f.text_field :sellername, autofocus: true, autocomplete: "sellername" %>
  </div>
  <!-- 省略 -->
<% end %>

<%= render "devise/shared/links" %>

2.変更できるようにしたい項目の追加

①設定ファイルの編集 ※ 必要に応じて、入力させたい項目を追加

app/views/devise/registrations/edit.html.erb

<h2>取扱者情報編集</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>
  <!-- 省略 -->

  <div class="field">
   <div class="field">
    <%= f.label :sellername, '取扱者' %><br />
    <%= f.text_field :sellername, autofocus: true, autocomplete: "sellername" %>
  </div>
  <!-- 省略 -->
<% end %>

<%= render "devise/shared/links" %>

3.ストロングパラメータの設定

①データベースに登録したい項目をストロングパラメータで指定する

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected
    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:sellername])
      devise_parameter_sanitizer.permit(:account_update, keys: [:sellername])
    end
end
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