{"id":606,"date":"2018-06-02T21:19:42","date_gmt":"2018-06-02T12:19:42","guid":{"rendered":"https:\/\/yuis-programming.com\/?p=606"},"modified":"2018-05-01T01:19:56","modified_gmt":"2018-04-30T16:19:56","slug":"rails-form_tag%e3%81%a8form_for%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9","status":"publish","type":"post","link":"https:\/\/yuis-programming.com\/?p=606","title":{"rendered":"Rails form_tag\u3068form_for\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<p>Rails form_tag\u3068form_for\u306e\u4f7f\u3044\u65b9\u3068\u3001\u305d\u308c\u305e\u308c\u306e\u9055\u3044\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>form_tag \u306e\u4f7f\u3044\u65b9<\/h2>\n<pre><code>\/\/ routes.rb\npost 'dev\/index'\nget 'dev\/form'\n\n\/\/ form.html.erb\n&lt;%= form_tag('\/dev\/index', method: :post) do %&gt;\n&lt;%= text_field_tag :name %&gt;\n&lt;%= text_area_tag :content %&gt;\n&lt;%= submit_tag(\"submit\") %&gt;\n&lt;% end %&gt;\n\n\/\/ index.html.erb\n&lt;%= params[:name] %&gt;\n<\/code><\/pre>\n<ul>\n<li>routes.rb \u306b\u3064\u3044\u3066<\/li>\n<\/ul>\n<p>\u30dd\u30b9\u30c8\u5148\u3092\u8a2d\u5b9a\u3059\u308b\u306e\u304c\u809d\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306f dev\/index \u306b\u5bfe\u3057\u3066\u30c7\u30fc\u30bf\u3092\u30dd\u30b9\u30c8\u3057\u305f\u3044\u306e\u3067\u3001\u305d\u308c\u3092<code>post<\/code>\u3068\u66f8\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<ul>\n<li>form.html.erb \u306b\u3064\u3044\u3066<\/li>\n<\/ul>\n<p>form_tag\u30e1\u30bd\u30c3\u30c9\u306e\u7b2c\u4e00\u5f15\u6570\u306b\u306f\u3001\u30dd\u30b9\u30c8\u5148\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<br \/>\n\u7b2c\u4e8c\u5f15\u6570\u4ee5\u964d\u306f\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3001\u3053\u3053\u3067\u306f\u66f8\u3044\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u30d5\u30a9\u30fc\u30e0\u306bCLASS\u3084ID\u3092\u5272\u308a\u5f53\u3066\u305f\u308a\u3067\u304d\u307e\u3059\u3002<br \/>\n<code>method:<\/code>\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u306a\u306e\u3067\u3001\u5225\u306b\u66f8\u304b\u306a\u304f\u3066\u3082\u5e73\u6c17\u3067\u3059\u3002<\/p>\n<ul>\n<li>index.html.erb \u306b\u3064\u3044\u3066<\/li>\n<\/ul>\n<p>form_tag\u306f\u3001params[:name]\u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u304c\u3001<br \/>\nform_for\u306f\u3001params[:userinfo][:name]\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>form_for \u306e\u4f7f\u3044\u65b9<\/h2>\n<pre><code>\/\/ routes.rb\npost 'dev\/index'\nget 'dev\/form'\n\n\/\/ dev_controller.rb\ndef form\n  @userinfo = Userinfo.new\nend\n\n\/\/ form.html.erb\n&lt;%= form_for(@userinfo , url: dev_index_path) do |f| %&gt;\n  &lt;%= f.text_field :name %&gt;\n  &lt;%= f.submit %&gt;\n&lt;% end %&gt;\n\n\/\/ index.html.erb\n&lt;%= params[:userinfo][:name] %&gt;\n<\/code><\/pre>\n<ul>\n<li>dev_controller.rb \u306b\u3064\u3044\u3066<\/li>\n<\/ul>\n<p>\u3053\u3053\u3067\u50d5\u306f\u3061\u3087\u3063\u3068\u30cf\u30de\u3063\u305f\u306e\u3067\u3059\u304c\u3002\u3069\u306e\u30b5\u30a4\u30c8\u3067\u3082\u7d39\u4ecb\u3057\u3066\u306a\u304b\u3063\u305f\u308a\u3067\u3002\u6c17\u3092\u3064\u3051\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3092\u66f8\u3044\u3066\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u306b\u30e2\u30c7\u30eb\u3092\u5b9a\u7fa9\u3057\u305f\u4e0a\u3067\u3001\u6b21\u306e\u3001form.html.erb\u306eform_for\u30e1\u30bd\u30c3\u30c9\u3067\u4f7f\u7528\u3059\u308b\u308f\u3051\u306a\u306e\u3067\u3002<br \/>\n\u3053\u308c\u66f8\u3044\u3066\u306a\u3044\u3068\u30cf\u30de\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>form.html.erb \u306b\u3064\u3044\u3066<\/li>\n<\/ul>\n<p>form_for\u30e1\u30bd\u30c3\u30c9\u306e\u7b2c\u4e00\u5f15\u6570\u306b\u306f\u3001\u5b9a\u7fa9\u3057\u305f\u30e2\u30c7\u30eb\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u3092\u66f8\u304d\u307e\u3059\u3002<br \/>\n\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3042\u308b<code>url<\/code>\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u3069\u3046\u3044\u3046\u3053\u3068\u304b\u3068\u3044\u3046\u3068\u3001form_for\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f<code>submit<\/code>\u3092\u62bc\u3057\u3066\u30dd\u30b9\u30c8\u3055\u308c\u308b\u5148\u304c\u3001<code>#create<\/code>\u3068\u6c7a\u307e\u3063\u3066\u3044\u307e\u3059\u3002\u306a\u306e\u3067\u3001<code>g scaffold<\/code>\u3068\u304b\u3057\u3066\u3044\u306a\u3044\u3067\u3001create\u304c\u306a\u3044\u3088\u30fc\u3063\u3066\u5834\u5408\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u305d\u3046\u3044\u3046\u6642\u306f\u3001\u81ea\u5206\u3067\u4efb\u610f\u306eURL\u306b\u98db\u3070\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u4f8b\u3067\u306f\u3001dev_index_path\u3068\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u3001&#8221;\u540d\u524d\u4ed8\u304d\u30eb\u30fc\u30c8&#8221;\u3068\u3044\u3046\u307f\u305f\u3044\u3067\u3059\u3002\u610f\u5473\u306f\u3001<code>\/dev\/index<\/code>\u3068\u540c\u69d8\u306e\u610f\u5473\u3067\u3059\u3002<\/p>\n<ul>\n<li>index.html.erb \u306b\u3064\u3044\u3066<\/li>\n<\/ul>\n<p>\u524d\u8ff0\u306e\u901a\u308a\u3001form_tag\u3068params\u3078\u306e\u683c\u7d0d\u306e\u4ed5\u65b9\u304c\u9055\u3046\u306e\u3067\u3001\u53d6\u308a\u51fa\u3057\u65b9\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rails form_tag\u3068form_for\u306e\u4f7f\u3044\u65b9\u3068\u3001\u305d\u308c\u305e\u308c\u306e\u9055\u3044\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 form_tag [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"acf":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8Rxwo-9M","_links":{"self":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/606"}],"collection":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=606"}],"version-history":[{"count":1,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/606\/revisions"}],"predecessor-version":[{"id":607,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/606\/revisions\/607"}],"wp:attachment":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}