{"id":418,"date":"2007-08-28T22:53:00","date_gmt":"2007-08-28T13:53:00","guid":{"rendered":"https:\/\/iwatakenichi.com\/2007\/08\/%e3%81%95%e3%81%8f%e3%82%89%e3%81%ae%e3%83%ac%e3%83%b3%e3%82%bf%e3%83%ab%e3%82%b5%e3%83%bc%e3%83%90%e3%81%a7ruby-on-rails%e3%82%92%e3%81%86%e3%81%94%e3%81%8b%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f\/"},"modified":"2007-08-28T22:53:00","modified_gmt":"2007-08-28T13:53:00","slug":"%e3%81%95%e3%81%8f%e3%82%89%e3%81%ae%e3%83%ac%e3%83%b3%e3%82%bf%e3%83%ab%e3%82%b5%e3%83%bc%e3%83%90%e3%81%a7ruby-on-rails%e3%82%92%e3%81%86%e3%81%94%e3%81%8b%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/iwatakenichi.com\/?p=418","title":{"rendered":"\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3067Ruby on Rails\u3092\u3046\u3054\u304b\u3057\u3066\u307f\u305f&#8230;\u3089\u304b\u306a\u308a\u9045\u3044\u304b\u3082&#8230;"},"content":{"rendered":"<p><a href=\"http:\/\/iwatakenichi.blogspot.com\/2007\/08\/ruby-on-rails-on-sakura.html\">\u305d\u306e1<\/a>\u3001<br \/>\n<a href=\"http:\/\/iwatakenichi.blogspot.com\/2007\/08\/ruby-on-rails-on-sakura-part2.html\">\u305d\u306e2<\/a>\u3067<br \/>\n<a href=\"http:\/\/www.sakura.ne.jp\/\">\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0<\/a>\u306bRuby on Rails\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001<br \/>\n\u52d5\u4f5c\u78ba\u8a8d\u3092\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3084\u308a\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u7c21\u5358\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u3001\u3069\u308c\u3050\u3089\u3044\u306e\u901f\u5ea6\u3067<br \/>\n\u3046\u3054\u304f\u306e\u304b\u78ba\u304b\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u984c\u6750\u306f\u300cToDo\u30ea\u30b9\u30c8\u300d\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e2\u306e\u7d9a\u304d\u3067\u3001$HOME\/Rails\u306e\u4e0b\u306bTodo\u3068\u3044\u3046\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre>\n% cd ~\/Rails\n% rails Todo\n<\/pre>\n<p>mySQL\u3067\u300ctodos\u300d\u3068\u3044\u3046\u540d\u524d\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002sql\u30b5\u30fc\u30d0\u30fc\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3001DB\u540d\u306f\u305d\u308c\u305e\u308c\u81ea\u5206\u306e\u3082\u306e\u306b\u304b\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>\n% mysql --host=mysqlhoge.db.sakura.ne.jp --user=xxxx --password=yyyy xxxx\n...\nmysql> create table todos (\n  -> id int primary key not null auto_increment,\n  -> desctiption varchar(100) not null,\n  -> done tinyint not null default 0);\nQuery OK, 0 rows affected (0.03 sec)\n\nmysql> desc todos;\n+-------------+--------------+------+-----+---------+----------------+\n| Field       | Type         | Null | Key | Default | Extra          |\n+-------------+--------------+------+-----+---------+----------------+\n| id          | int(11)      |      | PRI | NULL    | auto_increment |\n| desctiption | varchar(100) |      |     |         |                |\n| done        | tinyint(4)   |      |     | 0       |                |\n+-------------+--------------+------+-----+---------+----------------+\n3 rows in set (0.01 sec)\n<\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u304c\u51fa\u6765\u305f\u3089\u3001\u5404\u7a2e\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<ol>\n<li>config\/environment.rb\u306e\u8a2d\u5b9a<\/li>\n<li>public\/.htaccess\u306e\u8a2d\u5b9a<\/li>\n<li>tmp\u3068log\u306e\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3<\/li>\n<li>config\/database.yml\u306e\u8a2d\u5b9a<\/li>\n<\/ol>\n<p>(1)(2)(3)\u306f<a href=\"http:\/\/iwatakenichi.blogspot.com\/2007\/08\/ruby-on-rails-on-sakura-part2.html\">\u305d\u306e2<\/a>\u306b\u8a73\u3057\u3044\u306e\u3067\u3001\u305d\u3061\u3089\u3092\u3054\u53c2\u7167\u306e\u4e0a\u3001\u8a2d\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002(4)\u306f\u3001DB\u306e\u8a2d\u5b9a\u3067\u3059\u3002<br \/>\ndevelopment:\u3068test:\u3068production:\u306e3\u30bb\u30af\u30b7\u30e7\u30f3\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306fdevelopment:\u3092\u4e0b\u8a18\u306e\u3088\u3046\u306b<br \/>\n\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>\ndevelopment:\nadapter: mysql\ndatabase: xxxx\nusername: xxxx\npassword: yyyy\nhost: mysqlxx.db.sakura.ne.jp\n<\/pre>\n<p>\u6b21\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30e2\u30c7\u30eb\u3068\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>\n% cd ~\/Rails\/Todo\n% ruby script\/generate model Todo\n% ruby script\/generate controller todo\n<\/pre>\n<p>\u8a73\u3057\u3044\u8aac\u660e\u306f\u7701\u304d\u307e\u3059\u304c ^^;; app\/controllers\/todo_controller.rb \u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u304b\u3093\u3058\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>\n% cat app\/controllers\/todo_controller.rb\nclass TodoController &lt; ApplicationController\n model :todo\n def index\n   redirect_to :action => :list\n end\n def list\n   @items = Todo.find_all\n   @newitem = Todo.new\n end\n def edit\n  @edititem = Todo.find(params[:id])\n end\n def update\n  item = Todo.find(params[:id])\n  item.update_attributes(params[:todo])\n  if item.save\n        redirect_to(:action => \"list\")\n  else\n        render_text \"Couldn't update an item\"\n  end\n end\n def add_item\n  item = Todo.new(params[:todo])\n  if item.save\n        redirect_to(:action => \"list\")\n  else\n        render_text \"Couldn't add new item\"\n  end\n end\nend\n<\/pre>\n<p>app\/views\/todo\/edit.rhtml\u3092\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3002<\/p>\n<pre>\n% cat app\/views\/todo\/edit.rhtml\n&lt;html>\n  &lt;head>\n    &lt;title>Edit an item - My todo list&lt;\/title>\n  &lt;\/head>\n \n  &lt;body>\n  Edit the item:&lt;br>\n  &lt;% form_for :todo, @edititem, :url => { :action => :update , :id => @edititem } do |f| %>\n    &lt;%= f.check_box :done %>\n    &lt;%= f.text_field :description %>\n    &lt;%= submit_tag 'Update' %>\n  &lt;% end %>\n  &lt;\/body>\n&lt;\/html>\n<\/pre>\n<p>app\/views\/todo\/list.rhtml\u3092\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3002<\/p>\n<pre>\n% cat app\/views\/todo\/list.rhtml\n&lt;html>\n  &lt;head>\n    &lt;title>My todo list&lt;\/title>\n  &lt;\/head>\n \n  &lt;body>\n    &lt;% @items.each do |i| %>\n    &lt;%= check_box_tag(\"i\", i.done, (i.done == 1)) %>\n    &lt;%= i.description %>\n    &lt;%= link_to(\"Edit\", :action => \"edit\", :id => i.id) %>\n    &lt;br \/>\n    &lt;% end %>\n  &lt;hr>                                                   \n  &lt;% form_for :todo, @newitem, :url => { :action => :add_item } do |f| %>\n    New item:\n    &lt;%= f.text_field :description %>\n    &lt;%= submit_tag 'Add item' %>\n  &lt;% end %>\n  &lt;\/body>\n&lt;\/html>\n<\/pre>\n<p>config\/routes.rb\u306b\u4e0b\u306e2\u884c\u3092\u8ffd\u52a0\u3002<\/p>\n<pre>\nmap.connect '', :controller => \"todo\"\nmap.connect 'list', :controller => \"todo\", :action => 'list'\n<\/pre>\n<p>web\u3067\u898b\u3089\u308c\u308b\u3068\u3053\u308d\u304b\u3089\u3001public\u306b\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u3092\u5f35\u308b\u3002<\/p>\n<pre>\n% ln -s \/home\/xxxx\/Rails\/Todo\/public ~\/www\/todo\n<\/pre>\n<p>\u305d\u3093\u306a\u3053\u3093\u306a\u3067\u5b8c\u6210\u3002\u300c<a href=\"http:\/\/narak.sakura.ne.jp\/todo\/list\">My todo list<\/a>\u300d\u3067\u3046\u3054\u3044\u3066\u3044\u307e\u3059\u3002\u307f\u3066\u307f\u308b\u3068\u308f\u304b\u308a\u307e\u3059\u304c\u3001\u304b\u306a\u308a\u9045\u3044\u3002\u30ea\u30ed\u30fc\u30c9\u306b3\u79d2\u3050\u3089\u3044\u304b\u304b\u308a\u307e\u3059\u306d\u3002\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u306ffcgi\u304c\u4f7f\u3048\u306a\u304f\u3063\u3066\u3001cgi\u306a\u306e\u304c\u539f\u56e0\u307f\u305f\u3044\u3002\u3061\u3087\u3063\u3068\u3053\u306e\u9045\u3055\u3067\u306f\u30c4\u30ab\u30a8\u30ca\u30a4\u30ab\u30e2&#8230;<\/p>\n<p>\u53c2\u8003\u6587\u732e<\/p>\n<ol>\n<li><a href=\"http:\/\/narak.sakura.ne.jp\/todo\/list\">\u30c6\u30b9\u30c8<\/a><\/li>\n<li><a href=\"http:\/\/iwatakenichi.blogspot.com\/2007\/08\/ruby-on-rails-on-sakura.html\">\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u306bRuby on Rails\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"http:\/\/iwatakenichi.blogspot.com\/2007\/08\/ruby-on-rails-on-sakura-part2.html\">\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u306bRuby on Rails\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5 \u305d\u306e2<\/a><\/li>\n<li><a href=\"http:\/\/wiki.fdiary.net\/rails\/?TodoListTutorial\">Rail&#8217;s wiki<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u305d\u306e1\u3001 \u305d\u306e2\u3067 \u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u306bRuby on Rails\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001 \u52d5\u4f5c\u78ba\u8a8d\u3092\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3084\u308a\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u7c21\u5358\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u3001\u3069\u308c\u3050\u3089\u3044\u306e\u901f\u5ea6\u3067 \u3046\u3054\u304f\u306e\u304b\u78ba\u304b\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u984c\u6750\u306f\u300cToDo\u30ea\u30b9\u30c8\u300d\u3067\u3059\u3002 \u305d\u306e2\u306e\u7d9a\u304d\u3067\u3001$HOME\/Rails\u306e\u4e0b\u306bTodo\u3068\u3044\u3046\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3059\u3002 % cd ~\/Rails % rails Todo mySQL\u3067\u300ctodos\u300d\u3068\u3044\u3046\u540d\u524d\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002sql\u30b5\u30fc\u30d0\u30fc\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3001DB\u540d\u306f\u305d\u308c\u305e\u308c\u81ea\u5206\u306e\u3082\u306e\u306b\u304b\u3048\u3066\u304f\u3060\u3055\u3044\u3002 % mysql &#8211;host=mysqlhoge.db.sakura.ne.jp &#8211;user=xxxx &#8211;password=yyyy xxxx &#8230; mysql> create table todos ( -> id int primary key not null auto_increment, -> desctiption varchar(100) not null, -> done tinyint not null default 0); Query OK, 0 rows affected (0.03 sec) mysql> &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/iwatakenichi.com\/?p=418\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3067Ruby on Rails\u3092\u3046\u3054\u304b\u3057\u3066\u307f\u305f&#8230;\u3089\u304b\u306a\u308a\u9045\u3044\u304b\u3082&#8230;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,43,21],"tags":[],"class_list":["post-418","post","type-post","status-publish","format-standard","hentry","category-ruby","category-web","category-21"],"_links":{"self":[{"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=\/wp\/v2\/posts\/418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=418"}],"version-history":[{"count":0,"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions"}],"wp:attachment":[{"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iwatakenichi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}