{"id":2842,"date":"2021-11-11T20:08:33","date_gmt":"2021-11-11T11:08:33","guid":{"rendered":"https:\/\/suzutukiblog.com\/?p=2842"},"modified":"2022-01-15T02:36:57","modified_gmt":"2022-01-14T17:36:57","slug":"rails-11","status":"publish","type":"post","link":"https:\/\/suzutukiblog.com\/index.php\/2021\/11\/11\/rails-11\/","title":{"rendered":"Rails\u306e\u307e\u3068\u30817(ToDo\u30a2\u30d7\u30ea\u4f5c\u62101)"},"content":{"rendered":"<h3>TODO\u30a2\u30d7\u30ea\u3092\u4f5c\u308d\u3046!<\/h3>\n<h3>0:\u6a5f\u80fd\u306f\u306a\u306b\u304c\u3042\u308b\uff1f<\/h3>\n<p>\u65b0\u898f\u8ffd\u52a0\u6a5f\u80fd\u304c\u4ed8\u3044\u3066\u3044\u308b<\/p>\n<p>\u305d\u308c\u305e\u308c\u306b\u7de8\u96c6\u6a5f\u80fd\u3068\u524a\u9664\u6a5f\u80fd\u304c\u3064\u3044\u3066\u3044\u308b<\/p>\n<p>\u7a7a\u6587\u5b57\u3092\u8a8d\u3081\u306a\u3044(\u30b9\u30c8\u30ed\u30f3\u30b0\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc)<\/p>\n<p>5\u6587\u5b57\u4ee5\u4e0a\u3058\u3083\u306a\u3044\u3068\u30bf\u30a4\u30c8\u30eb\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3068\u8a00\u3046\u6587\u5b57\u5217\u3092\u8fd4\u3059<\/p>\n<p>\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3092\u62bc\u3059\u3068\u66f4\u65b0\u3057\u306a\u304f\u3066\u3082\u30b5\u30fc\u30d0\u30fc\u3068\u901a\u4fe1\u3092\u3057\u3066\u52d5\u7684\u51e6\u7406\u3092\u884c\u3046Ajax\u6a5f\u80fd\u3092\u4ed8\u3051\u308b<\/p>\n<p>cloud9\u3067\u958b\u767a\u3059\u308b<\/p>\n<h3>1:\u74b0\u5883\u69cb\u7bc9<\/h3>\n<p>\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u4ee5\u4e0b\u3092\u30b3\u30de\u30f3\u30c9<\/p>\n<pre><strong>\u30b8\u30a7\u30e0\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb(rails)<\/strong>\r\n<strong>gem install rails --version=\"5.1.4\" --no-document<\/strong>\r\n\r\n<strong>\u30d0\u30fc\u30b8\u30e7\u30f3\u30c1\u30a7\u30c3\u30af<\/strong>\r\n<strong>rails -v<\/strong>\r\n\r\n<strong>touch rails_projects<\/strong>\r\n\r\n<strong>cd \/home\/ec2-user\/environment\/rails_projects\/\r\n\r\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u3059\u308b\u3088\uff01<\/strong>\r\n<strong>rails new todo<\/strong>\r\n<strong>cd todo\r\n\r\n\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u4f5c\u6210\u3059\u308b\u3088\uff01<\/strong>\r\n<strong>rails g controller Tasks<\/strong><\/pre>\n<h3>2:\u30e2\u30c7\u30eb\u540d\u300cTask\u300d\u3092\u4f5c\u6210<\/h3>\n<p>\u5927\u6587\u5b57\u3067\u5358\u6570\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u76ee<\/p>\n<pre><strong>rails g model Task title:string done:boolean<\/strong><\/pre>\n<p>\u5f8c\u308d\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u69cb\u9020\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b<br \/>\n\u30bf\u30a4\u30c8\u30eb\u306f\u30ab\u30e9\u30e0\u540d\u3067String\u306f\u30c7\u30fc\u30bf\u306e\u578b\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3001<br \/>\ndone\u306f\u30bf\u30b9\u30af\u306e\u5b8c\u4e86\u306e\u72b6\u614b\u3092\u4fdd\u6301\u3059\u308b\u30ab\u30e9\u30e0\u3001<br \/>\n\u771f\u507d\u5024\u3092\u3068\u308b\u305f\u3081boolean\u3092\u578b\u3068\u3057\u3066\u3044\u308b\u3002<\/p>\n<p><strong>db\/migrate\/2021***********.rb<\/strong>\u306bcreate_tasks\u304c\u751f\u6210\u3055\u308c\u308b<\/p>\n<pre><strong>t.boolean :done, default: false <\/strong>#\u8ffd\u52a0<\/pre>\n<h3>3:DB\u30b9\u30ad\u30fc\u30de(DB\u306e\u69cb\u9020)\u3092DB\u306b\u53cd\u6620\u3055\u305b\u308b<\/h3>\n<pre><strong>rake db:migrate<\/strong><\/pre>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u898b\u308b\u3068\u304d<\/p>\n<pre><strong>rails db<\/strong>\r\n\r\n<strong>sqlite&gt; .schema<\/strong>\r\n<strong>CREATE TABLE \"schema_migrations\" (\"version\" varchar NOT NULL PRIMARY KEY);<\/strong>\r\n<strong>CREATE TABLE \"ar_internal_metadata\" (\"key\" varchar NOT NULL PRIMARY KEY, \"value\" varchar, \"created_at\" datetime NOT NULL, \"updated_at\" datetime NOT NULL);<\/strong>\r\n<strong>CREATE TABLE \"tasks\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \"title\" varchar, \"done\" boolean DEFAULT 'f', \"created_at\" datetime NOT NULL, \"updated_at\" datetime NOT NULL);<\/strong><\/pre>\n<p>\u2191\u3067\u8a2d\u5b9a\u304c\u308f\u304b\u308b<br \/>\n.exit\u3067sqlite\u304b\u3089\u51fa\u308b<br \/>\n<!--more--><\/p>\n<h3>4:\u521d\u671f\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>rails \u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u4f7f\u3046\u30e2\u30c7\u30eb\u306e\u64cd\u4f5c\u3084\u30c7\u30d0\u30c3\u30b0\u306b\u4fbf\u5229<\/p>\n<pre><strong>rails console\r\nTask.create(title: \"test1\")<\/strong>\r\n<strong>Task.create(title: \"test2\")<\/strong>\r\n<strong>exit<\/strong>\r\n\u30e2\u30c7\u30eb\u306a\u306e\u3067\u5927\u6587\u5b57\u306a\u3053\u3068\u306b\u6ce8\u610f\u3057\u3088\u3046<\/pre>\n<h3>5:\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u8a2d\u5b9a\u3057\u3088\u3046\uff01<\/h3>\n<p>config\/routes.rb<\/p>\n<pre>#\u2193\u3088\u304f\u4f7f\u3046\u4e00\u822c\u7684\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u307e\u3068\u3081\u3066\u751f\u6210\u3057\u3066\u304f\u308c\u308b\r\n<strong>resources :tasks\r\nroot 'tasks#index'<\/strong>\r\n#\u2191rootURL\u3067\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3068\u304dtasks\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\r\n#\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30a2\u30af\u30b7\u30e7\u30f3\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3002<\/pre>\n<pre><strong>rake routes<\/strong>\r\n\r\n<strong>Prefix    Verb   URI Pattern         Controller#Action<\/strong>\r\n<strong>tasks     GET \/tasks(.:format)          tasks#index<\/strong>\r\n<strong>          POST \/tasks(.:format)         tasks#create<\/strong>\r\n<strong>new_task  GET \/tasks\/new(.:format)      tasks#new<\/strong>\r\n<strong>edit_task GET \/tasks\/:id\/edit(.:format) tasks#edit<\/strong>\r\n<strong>task      GET \/tasks\/:id(.:format)      tasks#show<\/strong>\r\n<strong>          PATCH \/tasks\/:id(.:format)    tasks#update<\/strong>\r\n<strong>          PUT \/tasks\/:id(.:format)      tasks#update<\/strong>\r\n<strong>          DELETE \/tasks\/:id(.:format)   tasks#destroy<\/strong>\r\n<strong>root      GET    \/                      tasks#index<\/strong>\r\n\r\nPrefix: \u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u6642\u306b\u30d1\u30b9\u3092\u6307\u5b9a\u3059\u308b\u306e\u306b\u4f7f\u3046\u3002\r\nURL \u30d1\u30bf\u30fc\u30f3 \uff1a\u305d\u308c\u305e\u308c\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u6642\u306b \u884c\u308f\u308c\u308b\u30a2\u30af\u30b7\u30e7\u30f3<\/pre>\n<h3>6:\u4e00\u89a7\u753b\u9762\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u958b\u767a<\/h3>\n<p><strong>app\/controller\/tasks_controller.rb<\/strong><\/p>\n<pre><strong>def index<\/strong>\r\n<strong>  @tasks = task.all<\/strong>\r\n<strong>end<\/strong><\/pre>\n<p>@tasks\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5909\u6570\u3068\u547c\u3070\u308c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u57cb\u3081\u8fbc\u3081\u308b\u5024\u3001<br \/>\n\u3064\u307e\u308a\u3001\u30d3\u30e5\u30fc\u306b\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u3092\u6e21\u3059\u305f\u3081\u306b\u4f7f\u3046\u30a2\u30af\u30b7\u30e7\u30f3\u30e1\u30bd\u30c3\u30c9\u306b\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u6e21\u3059\u3002<br \/>\n<strong>Task.all<\/strong> \u30bf\u30b9\u30af\u30b9\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u3059\u3079\u3066\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<h3>7:\u4e00\u89a7\u753b\u9762\u306e\u958b\u767a<\/h3>\n<p><strong>app\/views\/tasks<\/strong>\u30d5\u30a9\u30eb\u30c0\u5185\u306b<strong>index.html.erb<\/strong>\u3092\u4f5c\u6210\u3057\u3066<br \/>\n<strong>app\/views\/index.html.erb<\/strong>\u3067\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;h1&gt;TODO\u30a2\u30d7\u30ea&lt;\/h1&gt;\r\n&lt;ul&gt;\r\n  &lt;% @tasks.each do |task| %&gt;\r\n    &lt;li&gt;\r\n      #check_box_tag\u306fHTML\u306e\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3092\u4f5c\u308b\u30d8\u30eb\u30d1\u30fc\r\n      &lt;%= check_box_tag '', '' %&gt;\r\n      &lt;%= task.title %&gt;\r\n     &lt;\/li&gt;\r\n  &lt;% end %&gt;\r\n&lt;\/ul&gt;<\/strong><\/pre>\n<p>\u30eb\u30d3\u30fc\u304c\u57cb\u3081\u8fbc\u3081\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067&lt;%\u3000%&gt;\u3084&lt;%= %&gt;\u3067\u56f2\u307e\u308c\u305f\u90e8\u5206\u306bRuby\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>@tasks\u306f\u8907\u6570\u306e\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u305e\u308ceach\u30671\u500b\u305a\u3064\u53d6\u308a\u51fa\u3057\u306a\u304c\u3089\u7a7a\u306e\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306etasks\u30c6\u30fc\u30d6\u30eb\u306e\u30bf\u30a4\u30c8\u30eb\u30ab\u30e9\u30e0\u306e\u30bf\u30a4\u30c8\u30eb\u3092\u51fa\u529b<\/p>\n<p>&lt;%\u4efb\u610f\u306e\u30b3\u30fc\u30c9%&gt;\u4efb\u610f\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u305f\u3044\u3068\u304d\u306b\u4f7f\u3046\u3088<\/p>\n<p>&lt;%=\u4f55\u3089\u304b\u306e\u5024\u3092\u8fd4\u3059\u5f0f\u3000%&gt;\u306a\u306b\u304b\u51fa\u529b\u3057\u305f\u3044\u3068\u304d\u306b\u4f7f\u3046\u3088<\/p>\n<p>rails s\u306b\u3066\u78ba\u8a8d\u30d6\u30e9\u30a6\u30b6\u3067\u78ba\u8a8d\u3057\u3066\u2193\u306e\u3088\u3046\u306b\u306a\u308c\u3070OK\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2846\" src=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2021\/04\/1977bdffcc4ef74bd96e88eecc762046.png\" alt=\"\" width=\"266\" height=\"232\" \/><\/p>\n<h3>8:\u65b0\u898f\u8ffd\u52a0\u753b\u9762\u306e\u958b\u767a<\/h3>\n<p><strong>views\/tasks\/index.html.erb<\/strong>\u3067<\/p>\n<p>link_to\u3067\u30cf\u30a4\u30d1\u30fc\u30ea\u30f3\u30af\u3092\u8ffd\u52a0\u3059\u308b\u30d8\u30eb\u30d1\u30fc\u3067\u65b0\u898f\u8ffd\u52a0\u306b\u30ea\u30f3\u30af\u6a5f\u80fd\u3092\u3064\u3051\u308b\u3088<\/p>\n<p><strong>&lt;%= link_to &#8216;\u65b0\u898f\u8ffd\u52a0&#8217;, new_task_path %&gt;<\/strong><br \/>\n\u203b\u307e\u3060\u30ea\u30f3\u30af\u5148\u3092\u4f5c\u3063\u3066\u306a\u3044\u305f\u3081\u62bc\u3059\u3068\u30a8\u30e9\u30fc<\/p>\n<p><strong>app\/views\/tasks<\/strong>\u306b\u30ea\u30f3\u30af\u5148\u306e\u65b0\u898f\u30d5\u30a1\u30a4\u30eb<strong>new.html.erb<\/strong>\u3092\u4f5c\u6210\u3059\u308b\u3088<\/p>\n<p><strong>app\/views\/new.html.erb<\/strong>\u306b\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3059\u308b<\/p>\n<pre><strong>&lt;h1&gt;\u65b0\u898f\u8ffd\u52a0\u753b\u9762&lt;\/h1&gt;<\/strong>\r\n<strong>  &lt;%= form_for @task do |f| %&gt;<\/strong>\r\n<strong>   &lt;p&gt;<\/strong>\r\n<strong>    &lt;%= f.label :title %&gt; &lt;br&gt;<\/strong>\r\n<strong>    &lt;%= f.text_field :title %&gt;<\/strong>\r\n<strong>   &lt;\/p&gt;<\/strong>\r\n<strong> &lt;p&gt;<\/strong>\r\n<strong>  &lt;%= f.submit %&gt;<\/strong>\r\n<strong> &lt;\/p&gt;<\/strong>\r\n<strong>&lt;% end %&gt;<\/strong><\/pre>\n<p>\uff46\u306f\u5909\u6570\u3060\u3088<br \/>\n<strong>form_for<\/strong>\u304c\u30e2\u30c7\u30eb\u306b\u95a2\u9023\u3057\u305f\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u308b\u30d8\u30eb\u30d1\u30fc<br \/>\n<strong>f.label:<\/strong> HTML\u306e\u30e9\u30d9\u30eb\u30bf\u30b0\u76f8\u5f53<br \/>\n<strong>f.text_field:<\/strong> \u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9<br \/>\n<strong>f.submit:<\/strong> \u30b5\u30d6\u30df\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u308b<\/p>\n<p>\u65b0\u898f\u8ffd\u52a0\u753b\u9762\u304c\u4f5c\u6210\u3055\u308c\u305f\u3089OK\u3060\u3088<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2847\" src=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2021\/04\/809c772df8e5954aaf3799929a8a19ca.png\" alt=\"\" width=\"340\" height=\"330\" srcset=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2021\/04\/809c772df8e5954aaf3799929a8a19ca.png 340w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2021\/04\/809c772df8e5954aaf3799929a8a19ca-300x291.png 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/p>\n<h3>9:\u65b0\u898f\u8ffd\u52a0\u6a5f\u80fd\u306e\u958b\u767a<\/h3>\n<p><strong>tasks_controller<\/strong>\u3067new\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0<\/p>\n<pre><strong>def new<\/strong>\r\n<strong>  @task = Task.new<\/strong>\r\n<strong>end<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570@task\u3092\u5b9a\u7fa9\u3057\u3066<br \/>\n<strong>new.html.erb<\/strong>\u306e@task\u306b\u30e9\u30d9\u30eb\u3068\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u3068<br \/>\nsubmit\u30dc\u30bf\u30f3\u3092\u751f\u6210\u3055\u305b\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u308b\u3002<\/p>\n<p>\u4fdd\u5b58\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u6642\u306b\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u5165\u529b\u3057\u305f\u5024\u3092<br \/>\n\u30b5\u30fc\u30d0\u306b\u9001\u4fe1\u3057\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u4fdd\u5b58\u3055\u305b\u308b\u3002<\/p>\n<p><strong>tasks_controller<\/strong>\u306b\u8ffd\u52a0<strong>tasks_params<\/strong>\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u5bfe\u7b56\u3067\u3084\u3063\u3066\u3044\u308b\u3088<\/p>\n<pre><strong>def create<\/strong>\r\n<strong>  @task = Task.new(task_params)<\/strong>\r\n<strong>end<\/strong>\r\n\r\n<strong> private<\/strong>\r\n<strong>  def task_params<\/strong>\r\n<strong>    params[:task].permit(:title)<\/strong>\r\n<strong>  end<\/strong>\r\n<strong>end<\/strong>\r\n\r\n#params\u306b\u306f\u30d5\u30a9\u30fc\u30e0\u304b\u3089\u9001\u3089\u308c\u305f\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u308b\u30d5\u30a9\u30fc\u30e0\u304b\u3089\r\n#\u9001\u3089\u308c\u3066\u304d\u305f\u30c7\u30fc\u30bf\u306e\u3046\u3061title\u30ab\u30e9\u30e0\u306e\u307f\u30c7\u30fc\u30bf\u306b\u4fdd\u5b58\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b<\/pre>\n<p>\u6b21\u306b<strong>tasks_controller<\/strong>\u306ecreate\u30a2\u30af\u30b7\u30e7\u30f3\u306b\u8a18\u8ff0\u3092\u8ffd\u52a0\u3059\u308b\u3088<\/p>\n<pre><strong>def create<\/strong>\r\n<strong>  @task = Task.new(task_params)<\/strong>\r\n<strong>   if @task.save<\/strong>\r\n<strong>     redirect_to root_path<\/strong>\r\n<strong>   else render 'new'<\/strong>\r\n<strong>end<\/strong><\/pre>\n<p>@task.save\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u66f8\u304d\u8fbc\u3092\u884c\u3046<br \/>\n\u30bb\u30fc\u30d6\u3067\u304d\u305f\u3089\u30eb\u30fc\u30c8URL\u306b\u98db\u3070\u3059 <strong>redirect_to root_path<\/strong><br \/>\n\u5931\u6557\u3057\u305f\u3089\u65b0\u898f\u767b\u9332\u753b\u9762\u306b\u98db\u3070\u3059 <strong>render &#8216;new&#8217;<\/strong><\/p>\n<p><strong>tasks_controller<\/strong>\u304c\u3053\u3046\u306a\u3063\u3066\u3044\u308c\u3070OK\u3060\u3088\u2193<\/p>\n<pre><strong>class TasksController &lt; ApplicationController<\/strong>\r\n\r\n<strong>  def index<\/strong>\r\n<strong>    @tasks = Task.all<\/strong>\r\n<strong>  end<\/strong>\r\n\r\n<strong>  def new<\/strong>\r\n<strong>    @task = Task.new<\/strong>\r\n<strong>  end<\/strong>\r\n\r\n<strong>  def create<\/strong>\r\n<strong>    @task = Task.new(task_params)<\/strong>\r\n<strong>      if @task.save<\/strong>\r\n<strong>        redirect_to root_path<\/strong>\r\n<strong>      else<\/strong>\r\n<strong>    render 'new'<\/strong>\r\n<strong>    end<\/strong>\r\n<strong>   end<\/strong>\r\n\r\n<strong>  private<\/strong>\r\n\r\n<strong>  def task_params<\/strong>\r\n<strong>    params[:task].permit(:title)<\/strong>\r\n<strong>  end<\/strong>\r\n<strong>end<\/strong><\/pre>\n<h3>10:\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u8ffd\u52a0<\/h3>\n<p>\u6b21\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3(\u4e88\u3081\u898f\u5b9a\u3055\u308c\u305f\u6761\u4ef6\u3084\u4ed5\u69d8\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u691c\u8a3c\u3059\u308b\u3053\u3068\u3002)\u3092\u8ffd\u52a0<br \/>\n\u7a7a\u767d\u30845\u6587\u5b57\u4ee5\u5185\u3067\u306a\u3044\u6642\u306b\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u306e\u3092\u4ed8\u52a0\u3059\u308b\u3088<\/p>\n<p><strong>app\/models\/task.rb\u3067\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3059\u308b\u3088<\/strong><\/p>\n<pre><strong>class Task &lt; ApplicationRecord<\/strong>\r\n<strong>  validates :title,<\/strong>\r\n<strong>  presence: { message: '\u30bf\u30a4\u30c8\u30eb\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044!'},<\/strong>\r\n<strong>  length: {minimum: 5, message: '5\u6587\u5b57\u4ee5\u4e0a\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\uff01'}<\/strong>\r\n<strong>end<\/strong><\/pre>\n<p>\u30e6\u30fc\u30b6\u30fc\u306b\u5bfe\u3057\u3066\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8fd4\u3059<\/p>\n<p><strong>app\/views\/tasks\/new.html.rb<\/strong>\u306b<\/p>\n<pre><strong>&lt;h1&gt;\u65b0\u898f\u8ffd\u52a0\u753b\u9762&lt;\/h1&gt;<\/strong>\r\n<strong>  &lt;%= form_for @task do |f| %&gt;<\/strong>\r\n<strong>   &lt;p&gt;<\/strong>\r\n<strong>    &lt;%= f.label :\u30bf\u30a4\u30c8\u30eb %&gt; &lt;br&gt;<\/strong>\r\n<strong>    &lt;%= f.text_field :title %&gt;<\/strong>\r\n<strong>     &lt;% if @task.errors.any? %&gt;<\/strong>\r\n<strong>      &lt;%= @task.errors.messages[:title][0] %&gt;<\/strong>\r\n<strong>     &lt;!--\u30a8\u30e9\u30fc\u304c2\u3064\u306e\u305f\u3081[0]--&gt;<\/strong>\r\n<strong>     &lt;% end %&gt;<\/strong>\r\n<strong>    &lt;\/p&gt;<\/strong>\r\n<strong>  &lt;p&gt;&lt;%= f.submit %&gt;&lt;\/p&gt;<\/strong>\r\n<strong>&lt;% end %&gt;<\/strong><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066<br \/>\n<strong>if @task.errors.any?<\/strong>\u306f\u30bf\u30b9\u30af\u30b9\u30e2\u30c7\u30eb\u3067\u4f55\u304b\u3057\u3089\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u3066\u3044\u305f\u3089<strong>task.rb<\/strong>\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<p><a href=\"https:\/\/suzutukiblog.com\/index.php\/2021\/04\/15\/rails-12\/\">\u305d\u306e8\u306b\u7d9a\u304d\u307e\u3059<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TODO\u30a2\u30d7\u30ea\u3092\u4f5c\u308d\u3046! 0:\u6a5f\u80fd\u306f\u306a\u306b\u304c\u3042\u308b\uff1f \u65b0\u898f\u8ffd\u52a0\u6a5f\u80fd\u304c\u4ed8\u3044\u3066\u3044\u308b \u305d\u308c\u305e\u308c\u306b\u7de8\u96c6\u6a5f\u80fd\u3068\u524a\u9664\u6a5f\u80fd\u304c\u3064\u3044\u3066\u3044\u308b \u7a7a\u6587\u5b57\u3092\u8a8d\u3081\u306a\u3044(\u30b9\u30c8\u30ed\u30f3\u30b0\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc) 5\u6587\u5b57\u4ee5\u4e0a\u3058\u3083\u306a\u3044\u3068\u30bf\u30a4\u30c8\u30eb\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3068\u8a00\u3046\u6587\u5b57\u5217 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2764,"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-2842","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-note","category-rails"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/2842","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=2842"}],"version-history":[{"count":7,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/2842\/revisions"}],"predecessor-version":[{"id":2862,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/2842\/revisions\/2862"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/media\/2764"}],"wp:attachment":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=2842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=2842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=2842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}