{"id":1442,"date":"2022-01-29T05:30:19","date_gmt":"2022-01-28T20:30:19","guid":{"rendered":"https:\/\/suzutukiblog.com\/?p=1442"},"modified":"2022-03-20T17:44:19","modified_gmt":"2022-03-20T08:44:19","slug":"form_for","status":"publish","type":"post","link":"https:\/\/suzutukiblog.com\/index.php\/2022\/01\/29\/form_for\/","title":{"rendered":"form_for\u304b\u3089form_with\u306b\u79fb\u884c\u3059\u308b\u306b\u306f\uff1f"},"content":{"rendered":"<h3>form_for\u304b\u3089form_with\u306b\u79fb\u884c\u3059\u308b<\/h3>\n<p><strong>before:users\/_form.html.erb<\/strong><\/p>\n<pre>&lt;%= form_<strong>for user<\/strong> do |f| %&gt;\r\n  &lt;%= render 'shared\/error_messages', object: f.object %&gt;\r\n    &lt;div class=\"inputWithIcon\"&gt;\r\n    &lt;%= f.text_field :name, class: 'form-field', placeholder: 'Your name' %&gt;\r\n    &lt;\/div&gt;\r\n  &lt;div class=\"inputWithIcon\"&gt;\r\n    &lt;%= f.email_field :email, class: 'form-field', placeholder: 'Email' %&gt;\r\n  &lt;\/div&gt;\r\n    &lt;%= f.password_field :password, class: 'form-field', placeholder: '\u30d1\u30b9\u30ef\u30fc\u30c9' %&gt;\r\n    &lt;%= f.password_field :password_confirmation, class: 'form-field', placeholder: '\u30d1\u30b9\u30ef\u30fc\u30c9\u78ba\u8a8d' %&gt;\r\n    &lt;%= f.submit \"\u767b\u9332\", class: \"btn btn-submit\" %&gt;\r\n&lt;% end %&gt;<\/pre>\n<p><strong>after:users\/_form.html.erb<\/strong><\/p>\n<pre>&lt;div class=\"new-todo-list-form\"&gt;\r\n  &lt;%= form_<strong>with model: user, local: true<\/strong> do |f| %&gt;\r\n    &lt;%= render 'shared\/error_messages', object: f.object %&gt;\r\n      &lt;div class=\"inputWithIcon\"&gt;\r\n      &lt;%= f.text_field :name, class: 'form-field', placeholder: 'Your name' %&gt;\r\n      &lt;\/div&gt;\r\n    &lt;div class=\"inputWithIcon\"&gt;\r\n      &lt;%= f.email_field :email, class: 'form-field', placeholder: 'Email' %&gt;\r\n    &lt;\/div&gt;\r\n      &lt;%= f.password_field :password, class: 'form-field', placeholder: '\u30d1\u30b9\u30ef\u30fc\u30c9' %&gt;\r\n      &lt;%= f.password_field :password_confirmation, class: 'form-field', placeholder: '\u30d1\u30b9\u30ef\u30fc\u30c9\u78ba\u8a8d' %&gt;\r\n      &lt;%= f.submit \"\u767b\u9332\", class: \"btn btn-submit\" %&gt;\r\n  &lt;% end %&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>local: true\u3092\u5165\u308c\u305f\u306e\u306f\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3055\u305b\u308b\u305f\u3081\u3002<\/p>\n<p><strong>shared\/_error_messages.html.erb<\/strong><\/p>\n<pre>&lt;% if object.errors.any? %&gt;\r\n  &lt;div id=\"error_explanation\"&gt;\r\n    &lt;div class=\"alert alert-danger\"&gt;\r\n      &lt;% object.errors.full_messages.each do |msg| %&gt;\r\n        &lt;li&gt;&lt;h4&gt;&lt;%= msg %&gt;&lt;\/h4&gt;&lt;\/li&gt;\r\n      &lt;% end %&gt;&lt;\/div&gt;\r\n  &lt;\/div&gt;\r\n&lt;% end %&gt;<\/pre>\n<p>local: true\u304c\u306a\u3044\u5834\u5408\u8868\u793a\u3055\u308c\u306a\u3044\u304c\u3001local: true\u3092\u8ffd\u52a0\u3055\u308c\u3070\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1445\" src=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2020\/08\/a8a11068d51fad3e915f16c53233535d-300x250.png\" alt=\"\" width=\"300\" height=\"250\" srcset=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2020\/08\/a8a11068d51fad3e915f16c53233535d-300x250.png 300w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2020\/08\/a8a11068d51fad3e915f16c53233535d-1024x855.png 1024w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2020\/08\/a8a11068d51fad3e915f16c53233535d-768x641.png 768w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2020\/08\/a8a11068d51fad3e915f16c53233535d-624x521.png 624w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2020\/08\/a8a11068d51fad3e915f16c53233535d.png 1354w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>\u30b9\u30b3\u30fc\u30d7\u306eprefix\u3092\u6307\u5b9a\u3059\u308b\u3068\u304d(\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u306a\u3069)<\/h3>\n<p><strong>before:sessions\/new.html.erb<\/strong><\/p>\n<pre>&lt;h1&gt;\u30ed\u30b0\u30a4\u30f3&lt;\/h1&gt;\r\n&lt;div class=\"login-form\"&gt;\r\n  &lt;%= <strong>form_for(:session, url: login_path<\/strong>) do |f| %&gt;\r\n    &lt;%= f.label :\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9, class: 'label' %&gt;\r\n    &lt;%= f.email_field :email, class: 'form-field' %&gt;\r\n    &lt;%= f.label :\u30d1\u30b9\u30ef\u30fc\u30c9, class: 'label' %&gt;\r\n    &lt;%= f.password_field :password, class: 'form-field' %&gt;\r\n    &lt;%= f.label :\u6b21\u56de\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b, class: \"checkbox inline\" do %&gt;\r\n      &lt;%= f.check_box :remember_me %&gt;\r\n      &lt;span&gt;\u6b21\u56de\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b&lt;\/span&gt;\r\n    &lt;% end %&gt;\r\n    &lt;%= f.submit \"\u30ed\u30b0\u30a4\u30f3\", class: \"btn btn-submit\" %&gt;\r\n  &lt;% end %&gt;\r\n  &lt;br&gt;\r\n  &lt;%= link_to(content_tag(:i, '\u306f\u3058\u3081\u3066\u306e\u65b9\u306f\u3053\u3061\u3089',\r\n                          class: \"fas fa-angle-double-right faa-horizontal animated-hover fa-pull-left\",\r\n                          style: \"color: sienna;\"), new_user_path) %&gt;\r\n&lt;\/div&gt;<\/pre>\n<p><strong>after:sessions\/new.html.erb<\/strong><\/p>\n<pre>&lt;h1&gt;\u30ed\u30b0\u30a4\u30f3&lt;\/h1&gt;\r\n&lt;div class=\"login-form\"&gt;\r\n  &lt;%= <strong>form_with scope: :session, url: login_path do<\/strong> |f| %&gt;\r\n    &lt;div class=\"inputWithIcon\"&gt;\r\n    &lt;%= f.email_field :email, class: 'form-field', placeholder: 'Email' %&gt;\r\n    &lt;%= f.password_field :password, class: 'form-field', placeholder: '\u30d1\u30b9\u30ef\u30fc\u30c9' %&gt;\r\n    &lt;\/div&gt;\r\n    &lt;%= f.label :\u6b21\u56de\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b, class: \"checkbox inline\" do %&gt;\r\n      &lt;%= f.check_box :remember_me %&gt;\r\n      &lt;span&gt;\u6b21\u56de\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b&lt;\/span&gt;\r\n    &lt;% end %&gt;\r\n    &lt;%= f.submit \"\u30ed\u30b0\u30a4\u30f3\", class: \"btn btn-submit\" %&gt;\r\n  &lt;% end %&gt;\r\n  &lt;br&gt;\r\n  &lt;%= link_to(content_tag(:i, '\u306f\u3058\u3081\u3066\u306e\u65b9\u306f\u3053\u3061\u3089',\r\n                          class: \"fas fa-angle-double-right faa-horizontal animated-hover fa-pull-left\",\r\n                          style: \"color: sienna;\"), new_user_path) %&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>scope\u3092\u52a0\u3048\u308b\u3060\u3051\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>form_for\u304b\u3089form_with\u306b\u79fb\u884c\u3059\u308b before:users\/_form.html.erb &lt;%= form_for user do |f| %&gt; &lt;%= render &#8216;shared\/e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[27,13],"tags":[],"class_list":["post-1442","post","type-post","status-publish","format-standard","hentry","category-programming-note","category-rails"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/1442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=1442"}],"version-history":[{"count":6,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/1442\/revisions"}],"predecessor-version":[{"id":5116,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/1442\/revisions\/5116"}],"wp:attachment":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=1442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=1442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=1442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}