{"id":12278,"date":"2020-11-22T14:35:37","date_gmt":"2020-11-22T05:35:37","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=12278"},"modified":"2023-05-27T22:44:23","modified_gmt":"2023-05-27T13:44:23","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%80%8c%e7%a2%ba%e8%aa%8d%e7%94%bb%e9%9d%a2%e3%80%8d%e3%81%ae%e5%ae%9f%e8%a3%85","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=12278","title":{"rendered":"\u3010Ruby on Rails\u3011\u300c\u78ba\u8a8d\u753b\u9762\u300d\u306e\u5b9f\u88c5"},"content":{"rendered":"<h2>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u8ffd\u52a0<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u300c\/users\u300d\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u306b\u65b0\u305f\u306b\u300cconfirm\u30a2\u30af\u30b7\u30e7\u30f3\u300d\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">  resources :users do\r\n    collection do\r\n      post :confirm\r\n    end\r\n  end<\/pre>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">confirm_users POST   \/users\/confirm(.:format)        users#confirm<\/pre>\n<h2>\u767b\u9332\u753b\u9762\u306e\u30bd\u30fc\u30b9<\/h2>\n<pre class=\"lang:default decode:true \">&lt;h1&gt;New User&lt;\/h1&gt;\r\n\r\n&lt;%= form_with(model: @user, local: true, url: confirm_users_path(@user)) do |form| %&gt;\r\n  &lt;% if @user.errors.any? %&gt;\r\n    &lt;div id=\"error_explanation\"&gt;\r\n      &lt;h2&gt;&lt;%= pluralize(user.errors.count, \"error\") %&gt; prohibited this user from being saved:&lt;\/h2&gt;\r\n\r\n      &lt;ul&gt;\r\n        &lt;% @user.errors.full_messages.each do |message| %&gt;\r\n          &lt;li&gt;&lt;%= message %&gt;&lt;\/li&gt;\r\n        &lt;% end %&gt;\r\n      &lt;\/ul&gt;\r\n    &lt;\/div&gt;\r\n  &lt;% end %&gt;\r\n\r\n  &lt;div class=\"field\"&gt;\r\n    &lt;%= form.label :name %&gt;\r\n    &lt;%= form.text_field :name %&gt;\r\n  &lt;\/div&gt;\r\n\r\n  &lt;div class=\"actions\"&gt;\r\n    &lt;%= form.submit %&gt;\r\n  &lt;\/div&gt;\r\n&lt;% end %&gt;\r\n\r\n&lt;%= link_to 'Back', users_path %&gt;<\/pre>\n<h2>\u78ba\u8a8d\u753b\u9762\u306e\u30bd\u30fc\u30b9<\/h2>\n<p>\u300c\u9001\u4fe1\u3059\u308b\u300d\u3068\u300c\u5165\u529b\u753b\u9762\u306b\u623b\u308b\u300d\u306esubmit\u3092\u540c\u3058\u30a2\u30af\u30b7\u30e7\u30f3\u306b\u6e21\u3057\u3066\u3044\u307e\u3059\u3002\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f\u5165\u529b\u753b\u9762\u306b\u623b\u308b\u30dc\u30bf\u30f3\u3067name\u3067back\uff08\u3069\u3093\u306a\u6587\u5b57\u5217\u3067\u3082\u826f\u3044\u3067\u3059\u3002\uff09\u3092\u6e21\u3057\u3066\u3044\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5074\u3067name\u306e\u6709\u7121\u3067\u51e6\u7406\u3092\u5206\u5c90\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/strong><\/span>\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;%= form_with(model: @user, local: true) do |form| %&gt;\r\n  &lt;%= form.hidden_field :name %&gt;\r\n\r\n  &lt;div class=\"field\"&gt;\r\n    &lt;%= @user.name %&gt;\r\n  &lt;\/div&gt;\r\n \r\n  &lt;div class=\"actions\"&gt;\r\n    &lt;%= form.submit '\u5165\u529b\u753b\u9762\u306b\u623b\u308b', :name =&gt; 'back' %&gt;\r\n  &lt;\/div&gt;\r\n\r\n  &lt;div class=\"actions\"&gt;\r\n    &lt;%= form.submit '\u9001\u4fe1\u3059\u308b' %&gt;\r\n  &lt;\/div&gt;\r\n&lt;% end %&gt;<\/pre>\n<h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306e\u30bd\u30fc\u30b9<\/h2>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u3001create(\u767b\u9332\u51e6\u7406)\u306e\u306a\u304b\u306e\u300cif params[:back]\u300d\u3067\u3059\u3002\u623b\u308b\u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u305f\u6642\u3068\u3001\u767b\u9332\u3092\u5b9f\u65bd\u3057\u305f\u3068\u304d\u3067\u51e6\u7406\u3092\u5206\u5c90\u3055\u305b\u308b\u3053\u3068\u306b\u6210\u529f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true  \">  def confirm\r\n    @user = User.new(user_params)\r\n  end\r\n\r\n  # POST \/users\r\n  # POST \/users.json\r\n  def create\r\n    @user = User.new(user_params)\r\n    if params[:back]\r\n      render :new\r\n      return\r\n\u3000\u3000\u3000\u3000end\r\n\r\n      respond_to do |format|\r\n        if @user.save\r\n          format.html { redirect_to @user, notice: 'User was successfully created.' }\r\n          format.json { render :show, status: :created, location: @user }\r\n        else\r\n          format.html { render :new }\r\n          format.json { render json: @user.errors, status: :unprocessable_entity }\r\n        end\r\n      end  \r\n  end<\/pre>\n","protected":false},"excerpt":{"rendered":"\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u8ffd\u52a0 \u4e0b\u8a18\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u300c\/users\u300d\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u8a2d\u5b9a\u306b\u65b0\u305f\u306b\u300cconfirm\u30a2\u30af\u30b7\u30e7\u30f3\u300d\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002 resources :users do collection do post :confirm  [&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\/12278"}],"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=12278"}],"version-history":[{"count":15,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/12278\/revisions"}],"predecessor-version":[{"id":20500,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/12278\/revisions\/20500"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12278"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}