{"id":4470,"date":"2025-08-20T17:10:47","date_gmt":"2025-08-20T08:10:47","guid":{"rendered":"https:\/\/www.kinryo.net\/?p=4470"},"modified":"2025-08-31T15:53:51","modified_gmt":"2025-08-31T06:53:51","slug":"%ef%bc%91%ef%bc%91%ef%bc%9a%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e6%a9%9f%e8%83%bd%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.kinryo.net\/?p=4470","title":{"rendered":"\uff11\uff11\uff1a\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u3051\u308b"},"content":{"rendered":"<p><strong><span style=\"color: #333333;\">\u57fa\u672c\u65b9\u91dd\uff1a<\/span><\/strong>\u3053\u308c\u304b\u3089\u4f5c\u308brails\u30a2\u30d7\u30ea\u306f\u793e\u5185\u306e\u7279\u5b9a\u90e8\u7f72\u306e\u793e\u54e1\u3057\u304b\u4f7f\u308f\u306a\u3044\u306e\u3067\u3001user\u306e\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306f\u4f5c\u308a\u307e\u3059\u304c\u3001\u5927\u3052\u3055\u306agem\u3084rails8\u304b\u3089\u5b9f\u88c5\u3055\u308c\u305fauthentication\u306a\u3069\u306f\u4f7f\u308f\u305a\u3001\u7ba1\u7406\u8005\u304c\u76f4\u63a5\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u4f5c\u308b\u3088\u3046\u306b\u3057\u3001\u30a2\u30d7\u30ea\u5074\u304b\u3089\u306f\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u30fc\u306e\u65b0\u898f\u4f5c\u6210\u3001\u7de8\u96c6\u3001\u524a\u9664\u306a\u3069\u4e00\u5207\u4f5c\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\n\u307e\u305a\u306f\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306e\u4f5c\u6210<br \/>\n<span><span style=\"color: #ff6600;\">[fuji@rails8 TourData]$<\/span> <span style=\"color: #008000;\">rails g model user name:string password_digest:string<\/span><br \/>\n<\/span> <span style=\"color: #ff6600;\">invoke active_record<\/span><br \/>\n<span style=\"color: #ff6600;\">create db\/migrate\/20250820061510_create_users.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">create app\/models\/user.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">invoke test_unit<\/span><br \/>\n<span style=\"color: #ff6600;\">create test\/models\/user_test.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">create test\/fixtures\/users.yml<\/span><br \/>\n<span><span style=\"color: #ff6600;\">[fuji@rails8 TourData]$<\/span> <span style=\"color: #008000;\">rails db:migrate<\/span><br \/>\n<\/span><span style=\"color: #ff6600;\">== 20250820061510 CreateUsers: migrating ======================================<\/span><br \/>\n<span style=\"color: #ff6600;\">&#8212; create_table(:users)<\/span><br \/>\n<span style=\"color: #ff6600;\">-&gt; 0.0873s<\/span><br \/>\n<span style=\"color: #ff6600;\">== 20250820061510 CreateUsers: migrated (0.0875s) =<\/span><br \/>\n<span>password_digest<\/span>\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u306f\u5e73\u6587\u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u308c\u308b\u3068\u3001\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306b\u306f\u6697\u53f7\u5316\u3057\u305f\u6587\u5b57\u5217\u304c\u5165\u308b\u3088\u3046\u306b\u306a\u308b\u3002<br \/>\n\u305d\u306e\u305f\u3081\u306bGEM\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067<br \/>\n<span><span style=\"color: #ff6600;\">[fuji@rails8 TourData]$<\/span> <\/span><span style=\"color: #008000;\">gedit Gemfile<\/span><\/p>\n<p><span style=\"color: #0000ff;\"># Use Active Storage variants [https:\/\/guides.rubyonrails.org\/active_storage_overview.html#transforming-images]<\/span><br \/>\n<span style=\"color: #0000ff;\"># gem &#8220;image_processing&#8221;, &#8220;~&gt; 1.2&#8221;<\/span><br \/>\n<span style=\"color: #0000ff;\">gem &#8220;spring-commands-rspec&#8221;<span style=\"color: #333333;\">\u3000\u2192 \u3053\u308c\u306f\u524d\u306b\u5165\u308c\u305f<\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">gem &#8220;bcrypt&#8221;<span style=\"color: #333333;\">\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u00a0 \u2192 \u3053\u308c\u3092\u8ffd\u8a18<\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">group :development, :test do0<\/span><br \/>\n\u3067\u304a\u7d04\u675f\u306e<br \/>\n<span style=\"color: #ff6600;\">[fuji@rails8 TourData]$ <\/span><span style=\"color: #008000;\">bundle<\/span><\/p>\n<p>\u3067\u6700\u521d\u306btest\u30e6\u30fc\u30b6\u30fc\u3067\u3082\u4f5c\u3063\u3066\u304a\u304f\u3001rails\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u4f5c\u308b\u304c\u305d\u306e\u524d\u306busers.rb\u3092\u8a2d\u5b9a\u3057\u3066\u304a\u304f<br \/>\n<span style=\"color: #ff6600;\">[fuji@rails8 TourData]$ <\/span><span style=\"color: #008000;\">gedit app\/models\/user.rb<\/span><br \/>\n<span style=\"color: #0000ff;\">class User &lt; ApplicationRecord<\/span><br \/>\n<span style=\"color: #0000ff;\">\u00a0\u00a0 has_secure_password<span style=\"color: #333333;\">\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u2192 \u3053\u308c\u3092\u8ffd\u8a18<\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">\u00a0\u00a0 validates :name, prsence: true, uniqueness: true<span style=\"color: #333333;\">\u3000\u2192 \u3053\u308c\u3092\u8ffd\u8a18<\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">end<\/p>\n<p><span style=\"color: #333333;\">rails\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u76f4\u63a5\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u308b<br \/>\n<\/span><\/span><span style=\"color: #ff6600;\"><\/span><span style=\"color: #ff6600;\">[fuji@rails8 TourData]$ <\/span><span style=\"color: #008000;\">rails c<\/span><br \/>\n<span style=\"color: #ff6600;\">tour-data(dev)&gt;<\/span> <span style=\"color: #008000;\">User.new( name: &#8216;\u30e6\u30fc\u30b6\u30fc\u540d&#8217;, password: &#8216;\u30d1\u30b9\u30ef\u30fc\u30c9&#8217;, password_confirmation: &#8216;\u30d1\u30b9\u30ef\u30fc\u30c9&#8217;).save<\/span><br \/>\n<span style=\"color: #ff6600;\">TRANSACTION (0.2ms) BEGIN \/*application=&#8217;TouData&#8217;*\/<\/span><br \/>\n<span style=\"color: #ff6600;\">User Create (1.0ms) INSERT INTO `users` (`name`, `password_digest`, `created_at`, `updated_at`) VALUES<br \/>\n<\/span><span style=\"color: #ff6600;\"><span style=\"color: #333333;\">\u5f8c\u7565<br \/>\n\u305d\u3057\u3066\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u51fa\u6765\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u305f\u3002<br \/>\n<\/span><\/span><\/p>\n<p>\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3092\u4f5c\u308b\u304c\u3001rails \u3067\u306f\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4f7f\u3046\u306e\u3067<br \/>\n<span style=\"color: #ff6600;\">[fuji@rails8 TourData]$<\/span> <span style=\"color: #008000;\">rails g controller Sessions new<\/span><br \/>\n<span style=\"color: #ff6600;\">create app\/controllers\/sessions_controller.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000route get &#8220;sessions\/new&#8221;<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000invoke erb<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000create app\/views\/sessions<\/span><br \/>\n\u5f8c\u7565<br \/>\nroute\u306e\u5909\u66f4\u3059\u308b\u304c\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3092\/login\u306b\u3057\u305f\u3044\u306e\u3067<br \/>\n<span style=\"color: #ff6600;\">[fuji@rails8 TourData]$<\/span> <span style=\"color: #008000;\">gedit config\/routes.rb<\/span><br \/>\n<span style=\"color: #0000ff;\">Rails.application.routes.draw do<\/span><br \/>\n<span style=\"color: #0000ff;\">\u3000#get &#8220;sessions\/new&#8221;<span style=\"color: #333333;\">\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057<\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">\u3000get &#8220;\/login&#8221;, to: &#8220;sessions\/new&#8221;<span style=\"color: #333333;\">\u3000\u3000\u3000\u3000\u3053\u3053\u304b\u3089<br \/>\n<span style=\"color: #0000ff;\">post &#8220;\/login&#8221;, to: &#8220;sessions#create&#8221;<\/span>\u3000\u3000\u3000\u3000\u2193<br \/>\n<span style=\"color: #0000ff;\">\u00a0\u00a0\u00a0 delete &#8216;\/logout&#8217;, to: &#8216;sessions#destroy&#8217;<\/span>\u3000\u3053\u3053\u307e\u3067\u8ffd\u8a18<br \/>\n<\/span><\/span>\u5f8c\u7565<br \/>\n\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u308b<br \/>\n<span style=\"color: #ff6600;\">[fuji@rails8 TourData]$ <\/span><span style=\"color: #008000;\">gedit \/app\/views\/sessions.new.html.erb<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;h1&gt;* LOG IN *&lt;\/h1&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;%= form_for(:session, url: login_path) do |f| %&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;%= f.label :name %&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;%= f.email_field :name %&gt;&lt;br&gt;&lt;br&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;%= f.label :password %&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;%= f.password_field :password %&gt;&lt;br&gt;&lt;br&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;%= f.submit &#8220;Log in&#8221; %&gt;<\/span><br \/>\n<span style=\"color: #0000ff;\">&lt;% end %&gt;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u65b9\u91dd\uff1a\u3053\u308c\u304b\u3089\u4f5c\u308brails\u30a2\u30d7\u30ea\u306f\u793e\u5185\u306e\u7279\u5b9a\u90e8\u7f72\u306e\u793e\u54e1\u3057\u304b\u4f7f\u308f\u306a\u3044\u306e\u3067\u3001user\u306e\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306f\u4f5c\u308a\u307e\u3059\u304c\u3001\u5927\u3052\u3055\u306agem\u3084rails8\u304b\u3089\u5b9f\u88c5\u3055\u308c\u305fauthentication\u306a\u3069\u306f\u4f7f\u308f\u305a\u3001\u7ba1\u7406\u8005\u304c\u76f4\u63a5\u30c7\u30fc\u30bf\u30fc &hellip; <a href=\"https:\/\/www.kinryo.net\/?p=4470\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"vkexunit_cta_each_option":"","footnotes":""},"categories":[28],"tags":[],"class_list":["post-4470","post","type-post","status-publish","format-standard","hentry","category-ruby-on-rails-almalinux9"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts\/4470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4470"}],"version-history":[{"count":13,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts\/4470\/revisions"}],"predecessor-version":[{"id":4510,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts\/4470\/revisions\/4510"}],"wp:attachment":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}