{"id":9168,"date":"2020-01-06T20:51:16","date_gmt":"2020-01-06T11:51:16","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=9168"},"modified":"2023-05-27T22:49:44","modified_gmt":"2023-05-27T13:49:44","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%80%8cdevise%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=9168","title":{"rendered":"\u3010Ruby on Rails\u3011\u300cdevise\u300d\u3001\u300cdevise_invitable\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>devise\u3068\u306f\uff1f<\/h2>\n<p>Rails\u306egem\u306e\u4e00\u3064\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h2>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u624b\u9806<\/h2>\n<p>Gemfile\u306b\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">gem 'devise'<\/pre>\n<p>bundle\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \">bundle install<\/pre>\n<h2>devise\u306e\u8a2d\u5b9a<\/h2>\n<p>devise\u306b\u95a2\u9023\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u3067\u81ea\u52d5\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails g devise:install<\/pre>\n<p>devise\u306b\u95a2\u9023\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u30e2\u30c7\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails g devise user<\/pre>\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u65bd\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails db:migrate<\/pre>\n<h2>\u4f7f\u3044\u65b9<\/h2>\n<p>\u57fa\u672c\u7684\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u6a5f\u80fd\u306e\u5229\u7528\u7bc4\u56f2\u3067\u3042\u308c\u3070\u3001<span style=\"color: #ff0000;\"><strong>\u4e00\u5ea6\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u3089devise\u306e\u8a8d\u8a3c\u753b\u9762\u306f\u30ed\u30b0\u30a2\u30a6\u30c8\u3059\u308b\u307e\u3067\u306f\u76ee\u306b\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002devise\u306e\u30d3\u30e5\u30fc\u3084\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u51e6\u7406\u81ea\u4f53\u3082\u76ee\u306b\u898b\u3048\u308b\u5834\u6240\u306b\u306f\u51fa\u3066\u3053\u306a\u3044\u306e\u3067\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306eDB\u5468\u308a\u4ee5\u5916\u306f\u30a2\u30d7\u30ea\u3068\u306f\u72ec\u7acb\u3057\u3066\u3044\u308b\u30a4\u30e1\u30fc\u30b8\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u305f\u3060\u3001HTML\u7b49\u306e\u30d3\u30e5\u30fc\u90e8\u5206\u306b\u95a2\u3057\u3066\u306f\u30b3\u30de\u30f3\u30c9\u3067\u30a2\u30d7\u30ea\u5185\u306b\u7d44\u307f\u8fbc\u3093\u3067\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u3002\uff09<\/strong><\/span><\/p>\n<h3>\u30b5\u30a4\u30f3\u30a2\u30c3\u30d7<\/h3>\n<p>Rails\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3057\u3066\u4e0b\u8a18URL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u30e6\u30fc\u30b6\u30fc\u306e\u30b5\u30a4\u30f3\u30a2\u30c3\u30d7\u30da\u30fc\u30b8\u304c\u3067\u304d\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost:3000\/users\/sign_up<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-9175\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2020\/01\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-01-06-21.30.24-300x231.png\" alt=\"\" width=\"300\" height=\"231\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2020\/01\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-01-06-21.30.24-300x231.png 300w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2020\/01\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-01-06-21.30.24.png 714w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u306a\u304a\u3001\u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u306b\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u518d\u5ea6\u30b5\u30a4\u30f3\u30a2\u30c3\u30d7\u306e\u753b\u9762\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3068\u3057\u3066\u3082Rails\u30a2\u30d7\u30ea\u306eroot\u306b\u98db\u3070\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u30b5\u30a4\u30f3\u30a4\u30f3\uff08\u30ed\u30b0\u30a4\u30f3\u753b\u9762\uff09<\/h3>\n<p>\u4e0b\u8a18URL\u306f\u30ed\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost:3000\/users\/sign_in<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-9172\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2020\/01\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-01-06-21.02.05-300x245.png\" alt=\"\" width=\"300\" height=\"245\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2020\/01\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-01-06-21.02.05-300x245.png 300w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2020\/01\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-01-06-21.02.05.png 684w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u306a\u304a\u3001\u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u306b\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u518d\u5ea6\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3068\u3057\u3066\u3082Rails\u30a2\u30d7\u30ea\u306eroot\u306b\u98db\u3070\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u30b5\u30a4\u30f3\u30a2\u30a6\u30c8\uff08\u30ed\u30b0\u30a2\u30a6\u30c8\uff09<\/h3>\n<p>\u300c<span class=\"s1\">\/users\/sign_out(<\/span>destroy_user_session_path)\u300d\u306b\u5bfe\u3057\u3066HTTP\u306eDELETE\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u30ed\u30b0\u30a2\u30a6\u30c8\u3055\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002Rails\u306elink_to\u30d3\u30e5\u30fc\u30d8\u30eb\u30d1\u30fc\u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;%= link_to '\u30ed\u30b0\u30a2\u30a6\u30c8', \r\n  destroy_user_session_path,\r\n  class: 'dropdown-item',\r\n  method: :delete\r\n%&gt;<\/pre>\n<h4>\u624b\u8efd\u306b\u30ed\u30b0\u30a2\u30a6\u30c8\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u305f\u3044\u5834\u5408<\/h4>\n<p>\u624b\u8efd\u306bURL\u3092\u53e9\u3044\u3066\u30ed\u30b0\u30a2\u30a6\u30c8\u51e6\u7406\u3092\u5b9f\u65bd\u3057\u305f\u3044\u5834\u5408\u306fGET\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u3082\u30ed\u30b0\u30a2\u30a6\u30c8\u304c\u884c\u308f\u308c\u308b\u3088\u3046\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3059\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true \">Rails.application.routes.draw do\r\n  devise_for :users\r\n  # For details on the DSL available within this file, see http:\/\/guides.rubyonrails.org\/routing.html\r\n\r\n  devise_scope :user do\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u2605\u8ffd\u52a0\r\n    get '\/users\/sign_out' =&gt; 'devise\/sessions#destroy'\u3000\u3000 \u2605\u8ffd\u52a0\r\n  end                                                      \u2605\u8ffd\u52a0\r\nend<\/pre>\n<p>\u8a66\u3057\u306b\u4e0a\u8a18\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u3092\u8ffd\u52a0\u5f8c\u306b\u4e0b\u8a18URL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308c\u3070\u30b5\u30a4\u30f3\u30a2\u30a6\u30c8\u304c\u884c\u308f\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost:3000\/users\/sign_out<\/pre>\n<h3>\u300c\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u300d\u3084\u300c\u30b5\u30a4\u30f3\u30a2\u30c3\u30d7\u753b\u9762\u300d\u306e\u30c7\u30b6\u30a4\u30f3\u3092\u5909\u3048\u305f\u3044\u5834\u5408<\/h3>\n<p>\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066devise\u306e\u30d3\u30e5\u30fc\u30d5\u30a1\u30a4\u30eb\u3092Rails\u30a2\u30d7\u30ea\u5185\u306b\u7d44\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails g devise:views<\/pre>\n<p>\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306a\u3089\u4e0b\u8a18HTML\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">views\/devise\/sessions\/new.html.erb<\/pre>\n<p>\u30b5\u30a4\u30f3\u30a2\u30c3\u30d7\u753b\u9762\u3067\u3042\u308c\u3070\u4e0b\u8a18HTML\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">views\/devise\/registrations\/new.html.erb<\/pre>\n<h3>\u30ed\u30b0\u30a4\u30f3\u3001\u30ed\u30b0\u30a2\u30a6\u30c8\u5f8c\u306b\u9077\u79fb\u3059\u308b\u753b\u9762\u8a2d\u5b9a<\/h3>\n<p>\u5404\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u57fa\u5e95\u30af\u30e9\u30b9\u3067\u3042\u308b<span style=\"color: #ff0000;\"><strong>\u300cApplicationController\u300d<\/strong><\/span>\u306b\u5bfe\u3057\u3066\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class ApplicationController &lt; ActionController::Base\r\n  # \u30ed\u30b0\u30a4\u30f3\u5f8c\u306b\u9077\u79fb\u3059\u308bpath\u3092\u8a2d\u5b9a\r\n  def after_sign_in_path_for(resource)\r\n    tool_index_path\r\n  end\r\n\r\n  # \u30ed\u30b0\u30a2\u30a6\u30c8\u5f8c\u306b\u9077\u79fb\u3059\u308bpath\u3092\u8a2d\u5b9a\r\n  def after_sign_out_path_for(resource)\r\n    tool_index_path\r\n  end\r\nend<\/pre>\n<h2>devise\u306e\u6a5f\u80fd<\/h2>\n<p>\u4f5c\u6210\u3057\u305fdevise\u306e\u30e6\u30fc\u30b6\u30fc\u30e2\u30c7\u30eb\u3092\u78ba\u8a8d\u3059\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30b7\u30f3\u30dc\u30eb\u304c\u305f\u304f\u3055\u3093\u3042\u308aUser\u30e2\u30c7\u30eb\u306b\u3066\u4f7f\u7528\u3067\u304d\u308b\u6a5f\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class User &lt; ApplicationRecord\r\n  # Include default devise modules. Others available are:\r\n  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable\r\n  devise :database_authenticatable, :registerable,\r\n         :recoverable, :rememberable, :validatable\r\nend<\/pre>\n<h3>\u30c7\u30d5\u30a9\u30eb\u30c8\u6a5f\u80fd<\/h3>\n<h4><span id=\"Database_Authenticatable\">Database Authenticatable<\/span><\/h4>\n<p>DB\u306b\u4fdd\u5b58\u3055\u308c\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u6b63\u3057\u3044\u304b\u691c\u8a3c\u3092\u884c\u3063\u3066\u304f\u308c\u307e\u3059\u3002\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6697\u53f7\u5316\u3082\u884c\u3063\u3066\u304f\u308c\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u5b9f\u52d9\u3067\u3082\u307b\u307c\u9593\u9055\u3044\u306a\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h4>Recoverable<\/h4>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u30ea\u30bb\u30c3\u30c8\u3057\u3066\u304f\u308c\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u5b9f\u52d9\u3067\u3082\u305f\u307e\u306b\u4f7f\u308f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u4ee5\u4e0b\u306e\u30d1\u30b9\u304c\u81ea\u52d5\u3067\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>new_{\u30e2\u30c7\u30eb\u540d}_password<span class=\"helper\">_path<\/span><\/li>\n<li>edit_{\u30e2\u30c7\u30eb\u540d}_password<span class=\"helper\">_path<\/span><\/li>\n<li>{\u30e2\u30c7\u30eb\u540d}_password<span class=\"helper\">_path<\/span><\/li>\n<\/ul>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u518d\u767a\u884c\u753b\u9762\u306f\u4e0b\u8a18\u3067\u3059\u3002\u30b5\u30a4\u30f3\u30a2\u30a6\u30c8\u3057\u3066\u3044\u308b\u72b6\u614b\u306e\u307f\u3067\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p>http:\/\/localhost:3000\/users\/password\/new<\/p>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u518d\u767a\u884c\u3059\u308b\u3068\u4e0b\u8a18\u306e\u30ab\u30e9\u30e0\u306b\u5024\u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>reset_password_token<\/li>\n<li>reset_password_sent_at<\/li>\n<\/ul>\n<h4>Registerable<\/h4>\n<p>User\u306e\u767b\u9332\u3001\u524a\u9664\u3001\u7de8\u96c6\u7b49\u3092\u884c\u3063\u3066\u304f\u308c\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u5b9f\u52d9\u3067\u3082\u305f\u307e\u306b\u4f7f\u308f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u8a2d\u5b9a\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u30d1\u30b9\u304c\u81ea\u52d5\u3067\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>cancel_{\u30e2\u30c7\u30eb\u540d}_registration<span class=\"helper\">_path<\/span><\/li>\n<li>new_{\u30e2\u30c7\u30eb\u540d}_registration<span class=\"helper\">_path<\/span><\/li>\n<li>edit_{\u30e2\u30c7\u30eb\u540d}_registration<span class=\"helper\">_path<\/span><\/li>\n<li>{\u30e2\u30c7\u30eb\u540d}_registration<span class=\"helper\">_path<\/span><\/li>\n<\/ul>\n<h4>Rememberable<\/h4>\n<p>20\u65e5\u9593\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u307e\u307e\u306b\u3059\u308b\u3068\u3044\u3046\u3088\u3046\u306a\u6c38\u7d9a\u30ed\u30b0\u30a4\u30f3\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u5b9f\u52d9\u3067\u3082\u305f\u307e\u306b\u4f7f\u308f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306b\u3042\u308b<span style=\"color: #ff0000;\"><strong>\u300cRemember me\u300d<\/strong><\/span>\u306e\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u969b\u306e\u6319\u52d5\u3067\u3059\u3002<\/p>\n<p>\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3068\u4e0b\u8a18\u306e\u30ab\u30e9\u30e0\u306b\u65e5\u4ed8\u304c\u5165\u308a\u8a08\u6e2c\u3055\u308c\u307e\u3059\u3002\u30ed\u30b0\u30a2\u30a6\u30c8\u3059\u308b\u3068\u30ab\u30e9\u30e0\u5185\u5bb9\u304cnil\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>remember_created_at<\/li>\n<\/ul>\n<h4>Validatable<\/h4>\n<p>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u5b9f\u52d9\u3067\u3082\u307b\u307c\u9593\u9055\u3044\u306a\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>\u305d\u306e\u4ed6\u6a5f\u80fd<\/h3>\n<h4><span id=\"Omniauthable\">Omniauthable<\/span><\/h4>\n<p>SNS\u8a8d\u8a3c\u3092\u884c\u3046\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3059\u3002\u4ed6\u306b\u3082Gem\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4><span id=\"Confirmable\">Confirmable<\/span><\/h4>\n<p>\u767b\u9332\u5f8c\u30e1\u30fc\u30eb\u3092\u9001\u308a\u30e1\u30fc\u30eb\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u672c\u767b\u9332\u3055\u305b\u308b\u3068\u3044\u3046\u4ed5\u7d44\u307f\u3092\u5b9f\u88c5\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h4>Trackable<\/h4>\n<p>\u30ed\u30b0\u30a4\u30f3\u6642\u9593\u3084\u56de\u6570\u7b49\u3092\u4fdd\u7ba1\u3057\u3066\u304a\u304d\u5206\u6790\u306b\u5f79\u7acb\u3066\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u5b9f\u52d9\u3067\u3082\u307b\u307c\u9593\u9055\u3044\u306a\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h4><span id=\"Timeoutable\">Timeoutable<\/span><\/h4>\n<p>\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u307e\u307e\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u7834\u68c4\u3057\u307e\u3059\u3002<\/p>\n<h4><span id=\"Lockable\">Lockable<\/span><\/h4>\n<p>\u30ed\u30b0\u30a4\u30f3\u306b\u4f55\u5ea6\u3082\u5931\u6557\u3059\u308b\u3068\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u30ed\u30c3\u30af\u3055\u305b\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb<\/h2>\n<p>\u300crails g devise user\u300d\u306b\u3088\u308a\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u4f5c\u6210\u3055\u308c\u305f\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u4e0a\u8a18\u3067\u7d39\u4ecb\u3057\u305f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u4f7f\u3046\u6a5f\u80fd\u5225(<span id=\"Database_Authenticatable\">Database Authenticatable\u7b49<\/span>)\u306b\u5fc5\u8981\u306a\u30ab\u30e9\u30e0\u540d\u3084\u8a2d\u5b9a\u7b49\u304c\u8a18\u8f09\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/strong><\/span>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u4f7f\u7528\u3055\u308c\u306a\u3044\u6a5f\u80fd\u306f\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f\u30b3\u30e1\u30f3\u30c8\u3092\u5916\u3057\u3066\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\"># frozen_string_literal: true\r\n\r\nclass DeviseCreateUsers &lt; ActiveRecord::Migration[5.2]\r\n  def change\r\n    create_table :users do |t|\r\n      ## Database authenticatable\r\n      t.string :email,              null: false, default: \"\"\r\n      t.string :encrypted_password, null: false, default: \"\"\r\n\r\n      ## Recoverable\r\n      t.string   :reset_password_token\r\n      t.datetime :reset_password_sent_at\r\n\r\n      ## Rememberable\r\n      t.datetime :remember_created_at\r\n\r\n      ## Trackable\r\n      # t.integer  :sign_in_count, default: 0, null: false\r\n      # t.datetime :current_sign_in_at\r\n      # t.datetime :last_sign_in_at\r\n      # t.string   :current_sign_in_ip\r\n      # t.string   :last_sign_in_ip\r\n\r\n      ## Confirmable\r\n      # t.string   :confirmation_token\r\n      # t.datetime :confirmed_at\r\n      # t.datetime :confirmation_sent_at\r\n      # t.string   :unconfirmed_email # Only if using reconfirmable\r\n\r\n      ## Lockable\r\n      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts\r\n      # t.string   :unlock_token # Only if unlock strategy is :email or :both\r\n      # t.datetime :locked_at\r\n\r\n\r\n      t.timestamps null: false\r\n    end\r\n\r\n    add_index :users, :email,                unique: true\r\n    add_index :users, :reset_password_token, unique: true\r\n    # add_index :users, :confirmation_token,   unique: true\r\n    # add_index :users, :unlock_token,         unique: true\r\n  end\r\nend<\/pre>\n<h2>\u73fe\u5728\u30ed\u30b0\u30a4\u30f3\u4e2d\u3067\u3042\u308b\u304b\u306e\u5224\u5b9a<\/h2>\n<p>\u73fe\u5728\u30ed\u30b0\u30a4\u30f3\u4e2d\u306e\u30e6\u30fc\u30b6\u30fc\u306f<span style=\"color: #ff0000;\"><strong>\u300ccurrent_user\u300d<\/strong><\/span>\u3068\u3044\u3046User\u30e2\u30c7\u30eb\u306e\u5909\u6570\u306b\u5024\u304c\u5165\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u30ed\u30b0\u30a4\u30f3\u4e2d\u3067\u3042\u308c\u3070\u4e0b\u8a18\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3048\u3070true\u304c\u8fd4\u308a\u3001\u30ed\u30b0\u30a2\u30a6\u30c8\u4e2d\u3067\u3042\u308c\u3070false\u304c\u8fd4\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">current_user.present?<\/pre>\n<h2>\u4e00\u822c\u30e6\u30fc\u30b6\u30fc\u3068\u7ba1\u7406\u8005\u3092\u5206\u3051\u308b\u3002<\/h2>\n<p>devise\u306e\u30e6\u30fc\u30b6\u30fc\u30c6\u30fc\u30d6\u30eb\u306badmin\u3068\u3044\u3046\u7ba1\u7406\u8005\u3092\u793a\u3059\u30d5\u30e9\u30b0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails g migration add_admin_to_users admin:boolean<\/pre>\n<p>\u751f\u6210\u3055\u308c\u305f\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails db:migrate<\/pre>\n<p>\u5f8c\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u5185\u3067\u4e0b\u8a18\u306e\u3088\u3046\u306a\u8a18\u8ff0\u3092\u5b9f\u65bd\u3059\u308c\u3070\u7ba1\u7406\u8005\u7279\u6709\u306e\u51e6\u7406\u3092\u5b9f\u88c5\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">if current_user.try(:admin?)\r\n  #\u30e6\u30fc\u30b6\u30fc\u304c\u7ba1\u7406\u8005\u3067\u3042\u308b\u5834\u5408\u306b\u884c\u308f\u305b\u305f\u3044\u51e6\u7406\r\nend<\/pre>\n<h2>devise_invitable\u3068\u306f\uff1f<\/h2>\n<p>devise\u306b\u62db\u5f85\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<h2>\u5b9f\u88c5\u624b\u9806<\/h2>\n<p>Gemfile\u306b\u4e0b\u8a18\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">gem 'devise_invitable'<\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<pre class=\"lang:default decode:true \">bundle install<\/pre>\n<p>\u7ffb\u8a33\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \">rails g devise_invitable:install<\/pre>\n<p>devise\u3068\u7d10\u3065\u3044\u3066\u3044\u308b\u30e2\u30c7\u30eb\u306b\u300cdevise_invitable\u300d\u7528\u306e\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \">rails g devise_invitable User<\/pre>\n<h3>\u8ffd\u52a0\u3055\u308c\u308b\u30ab\u30e9\u30e0<\/h3>\n<table>\n<tbody>\n<tr>\n<th>\u30ab\u30e9\u30e0\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>invitation_token<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>invitation_created_at<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>invitation_sent_at<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>invitation_accepted_at<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>invitation_limit<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>invited_by_type<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>invited_by_id<\/td>\n<td>\u3069\u306e\u30e6\u30fc\u30b6\u30fc\u306b\u62db\u5f85\u3055\u308c\u305f\u304b\u306eID\u304c\u5165\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>invitations_count<\/td>\n<td>\u62db\u5f85\u30e1\u30fc\u30eb\u3092\u9001\u3063\u305f\u4eba\u6570\u304c\u81ea\u52d5\u3067\u30ab\u30a6\u30f3\u30c8\u3055\u308c\u308b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u30d3\u30e5\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">rails g devise_invitable:views<\/pre>\n<p>\u306a\u304a\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u51e6\u7406\u304b\u3089\u5909\u3048\u305f\u3044\u5834\u5408\u306f\u300cDevise::InvitationsController\u300d\u3092<span style=\"color: #ff0000;\"><strong>\u7d99\u627f\u3057\u3066\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u4f5c\u6210\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<pre class=\"lang:default decode:true\">class Users::InvitationsController &lt; Devise::InvitationsController\r\n  def new\r\n    super\r\n  end\r\n\r\n  def create\r\n    super\r\n  end\r\n\r\n  def edit\r\n    super\r\n  end\r\n\r\n  def update\r\n    super\r\n  end\r\n\r\n  def destroy\r\n    super\r\n  end\r\nend<\/pre>\n<h3>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u3092\u8ffd\u52a0<\/h3>\n<pre class=\"lang:default decode:true\">  devise_for :users, controllers: {\r\n    invitations: 'users\/invitations'\r\n  }<\/pre>\n<p>\u307e\u305f\u3001\u300capp\/views\/devise\/mailer\/invitation_instructions.html.erb\u300d\u306b\u3042\u308b\u4e0b\u8a18\u5185\u5bb9\u304c\u30e1\u30fc\u30eb\u9001\u4fe1\u5185\u5bb9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;p&gt;&lt;%= t(\"devise.mailer.invitation_instructions.hello\", email: @resource.email) %&gt;&lt;\/p&gt;\r\n\r\n&lt;p&gt;&lt;%= t(\"devise.mailer.invitation_instructions.someone_invited_you\", url: root_url) %&gt;&lt;\/p&gt;\r\n\r\n&lt;p&gt;&lt;%= link_to t(\"devise.mailer.invitation_instructions.accept\"), accept_invitation_url(@resource, invitation_token: @token) %&gt;&lt;\/p&gt;\r\n\r\n&lt;% if @resource.invitation_due_at %&gt;\r\n  &lt;p&gt;&lt;%= t(\"devise.mailer.invitation_instructions.accept_until\", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %&gt;&lt;\/p&gt;\r\n&lt;% end %&gt;\r\n\r\n&lt;p&gt;&lt;%= t(\"devise.mailer.invitation_instructions.ignore\") %&gt;&lt;\/p&gt;<\/pre>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3001\u300croot_url\u300d\u3068\u3044\u3046\u69cb\u6587\u3092\u4f7f\u3063\u3066\u3044\u3066\u4e0b\u8a18\u306e\u8a2d\u5b9a\u3092\u3057\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>config\/environments\/development.rb<\/h3>\n<pre class=\"lang:default decode:true  \">config.action_mailer.default_url_options = { host: '\u4efb\u610f\u306e\u30c9\u30e1\u30a4\u30f3\u540d' }<\/pre>\n","protected":false},"excerpt":{"rendered":"devise\u3068\u306f\uff1f Rails\u306egem\u306e\u4e00\u3064\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3057\u3066\u304f\u308c\u307e\u3059\u3002 \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u624b\u9806 Gemfile\u306b\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u3059\u308b\u3002 gem 'devise' bundle\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002 bundle inst [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9168"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9168"}],"version-history":[{"count":22,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9168\/revisions"}],"predecessor-version":[{"id":20517,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9168\/revisions\/20517"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9168"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}