{"id":25265,"date":"2024-03-21T15:54:27","date_gmt":"2024-03-21T06:54:27","guid":{"rendered":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25265"},"modified":"2024-03-21T15:54:29","modified_gmt":"2024-03-21T06:54:29","slug":"ruby-on-rails-todo%e3%83%aa%e3%82%b9%e3%83%88","status":"publish","type":"post","link":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25265","title":{"rendered":"Ruby on Rails Todo\u30ea\u30b9\u30c8"},"content":{"rendered":"\n<p>Ruby on Rails\u3092\u4f7f\u7528\u3057\u3066Todo\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002\u307e\u305a\u306f\u3001\u4ee5\u4e0b\u306e\u624b\u9806\u306b\u5f93\u3063\u3066\u65b0\u3057\u3044Rails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30bf\u30fc\u30df\u30ca\u30eb\u3092\u958b\u3044\u3066\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4fdd\u5b58\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001\u65b0\u3057\u3044Rails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>rails new todo_list<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>\u4f5c\u6210\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>cd todo_list<\/code><\/p>\n\n\n\n<p>\u6b21\u306b\u3001Todo\u30ea\u30b9\u30c8\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Todo\u30a2\u30a4\u30c6\u30e0\u3092\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u30e2\u30c7\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><\/li>\n<\/ol>\n\n\n\n<p><code>rails generate model TodoItem title:string description:text completed:boolean<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u3001\u65b0\u3057\u3044\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>rails db:migrate<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>Todo\u30a2\u30a4\u30c6\u30e0\u3092\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>rails generate controller TodoItems<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><code>config\/routes.rb<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30eb\u30fc\u30c8\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>Rails.application.routes.draw do resources :todo_items root 'todo_items#index' end<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li><code>app\/controllers\/todo_items_controller.rb<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u3001\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>class TodoItemsController &lt; ApplicationController before_action :set_todo_item, only: [:show, :edit, :update, :destroy] def index @todo_items = TodoItem.all end def show end def new @todo_item = TodoItem.new end def edit end def create @todo_item = TodoItem.new(todo_item_params) if @todo_item.save redirect_to @todo_item, notice: 'Todo item was successfully created.' else render :new end end def update if @todo_item.update(todo_item_params) redirect_to @todo_item, notice: 'Todo item was successfully updated.' else render :edit end end def destroy @todo_item.destroy redirect_to todo_items_url, notice: 'Todo item was successfully destroyed.' end private def set_todo_item @todo_item = TodoItem.find(params[:id]) end def todo_item_params params.require(:todo_item).permit(:title, :description, :completed) end end<\/code><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\">\n<li><code>app\/views\/todo_items<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u3001\u5fc5\u8981\u306a\u30d3\u30e5\u30fc\u30d5\u30a1\u30a4\u30eb\uff08index\u3001show\u3001new\u3001edit\uff09\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>app\/views\/todo_items\/index.html.erb<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u3001Todo\u30a2\u30a4\u30c6\u30e0\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n\n\n\n<p><code>&lt;h1&gt;Todo Items&lt;\/h1&gt; &lt;%= link_to 'New Todo Item', new_todo_item_path %&gt; &lt;ul&gt; &lt;% @todo_items.each do |todo_item| %&gt; &lt;li&gt; &lt;%= link_to todo_item.title, todo_item %&gt; &lt;% if todo_item.completed %&gt; (Completed) &lt;% else %&gt; (Pending) &lt;% end %&gt; &lt;\/li&gt; &lt;% end %&gt; &lt;\/ul&gt;<\/code><\/p>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u57fa\u672c\u7684\u306aTodo\u30ea\u30b9\u30c8\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5b8c\u6210\u3057\u307e\u3057\u305f\u3002 <code>rails server<\/code> \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066Rails\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3057\u3001 <a>http:\/\/localhost:3000\/todo_items<\/a> \u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/a\/ALm5wu2ENKlzmqkRyJdXJdiEFTtGVYqWZdKDagoVmNJ3ag=s96-c\" alt=\"User\"\/><\/figure>\n\n\n\n<p>You<\/p>\n\n\n\n<p>No template for interactive request TodoItemsController#new is missing a template for request formats: text\/html NOTE! Unless told otherwise, Rails expects an action to render a template with the same name, contained in a folder named after its controller. If this controller is an API responding with 204 (No Content), which does not require a template, then this error will occur when trying to access it via browser, since we expect an HTML template to be rendered for such requests. If that&#8217;s the case, carry on. ChatGPT<\/p>\n\n\n\n<p>ChatGPT<\/p>\n\n\n\n<p>\u3053\u306e\u30a8\u30e9\u30fc\u306f\u3001<code>TodoItemsController#new<\/code> \u30a2\u30af\u30b7\u30e7\u30f3\u306b\u5bfe\u5fdc\u3059\u308b\u30d3\u30e5\u30fc\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u305f\u3081\u306b\u767a\u751f\u3057\u3066\u3044\u307e\u3059\u3002Rails\u306f\u901a\u5e38\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3068\u540c\u3058\u540d\u524d\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u3042\u308b\u540c\u3058\u540d\u524d\u306e\u30d3\u30e5\u30fc\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u671f\u5f85\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u306f\u3001<code>app\/views\/todo_items<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b <code>new.html.erb<\/code> \u3068\u3044\u3046\u540d\u524d\u306e\u30d3\u30e5\u30fc\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5f8c\u3001\u65b0\u3057\u3044Todo\u30a2\u30a4\u30c6\u30e0\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u30d5\u30a9\u30fc\u30e0\u3092\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>erbCopy code<\/p>\n\n\n\n<p><code>&lt;!-- app\/views\/todo_items\/new.html.erb --&gt; &lt;h1&gt;New Todo Item&lt;\/h1&gt; &lt;%= form_with(model: @todo_item, url: todo_items_path) do |form| %&gt; &lt;%= form.label :title %&gt; &lt;%= form.text_field :title %&gt; &lt;%= form.label :description %&gt; &lt;%= form.text_area :description %&gt; &lt;%= form.submit 'Create Todo Item' %&gt; &lt;% end %&gt; &lt;%= link_to 'Back', todo_items_path %&gt;<\/code><\/p>\n\n\n\n<p>\u3053\u308c\u3067\u3001<code>TodoItemsController#new<\/code> \u30a2\u30af\u30b7\u30e7\u30f3\u306b\u5bfe\u3059\u308b\u30d3\u30e5\u30fc\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002\u518d\u5ea6\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u30a8\u30e9\u30fc\u306f\u89e3\u6d88\u3055\u308c\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ruby on Rails\u3092\u4f7f\u7528\u3057\u3066Todo\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002\u307e\u305a\u306f\u3001\u4ee5\u4e0b\u306e\u624b\u9806\u306b\u5f93\u3063\u3066\u65b0\u3057\u3044Rails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002 rails new todo_list cd todo_list &hellip; <a href=\"http:\/\/www.tyosuke20xx.com\/blog\/?p=25265\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Ruby on Rails Todo\u30ea\u30b9\u30c8&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[4,6],"tags":[3,127],"class_list":["post-25265","post","type-post","status-publish","format-standard","hentry","category-programming","category-web","tag-programming","tag-ruby-on-rails"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25265"}],"version-history":[{"count":1,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25265\/revisions"}],"predecessor-version":[{"id":25266,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25265\/revisions\/25266"}],"wp:attachment":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25265"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}