{"id":12,"date":"2005-06-29T20:04:23","date_gmt":"2005-06-29T11:04:23","guid":{"rendered":"http:\/\/www.gesource.jp\/weblog\/?p=12"},"modified":"2017-07-17T00:38:14","modified_gmt":"2017-07-16T15:38:14","slug":"markdown","status":"publish","type":"post","link":"https:\/\/www.gesource.jp\/weblog\/?p=12","title":{"rendered":"Ruby on Rails\u3067\u4e00\u884c\u63b2\u793a\u677f\u3092\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"<p>2007\u5e744\u670829\u65e5\u8ffd\u8a18\uff1a<a href=\"http:\/\/www.gesource.jp\/weblog\/archives\/2007\/04\/ruby_on_railsruby_on_rails_12.html\">Ruby on Rails 1.2\u5bfe\u5fdc\u7248<\/a>\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Ruby on Rails\u306e\u7df4\u7fd2\u306b\u3001\u7c21\u5358\u306a\u63b2\u793a\u677f\u3092\u4f5c\u6210\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4f5c\u6210<\/p>\n<p>MySQL\u3092\u4f7f\u7528\u3057\u3066\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3002<\/p>\n<pre><code>CREATE DATABASE `bbs`;\n<\/code><\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3002<\/p>\n<pre><code>CREATE TABLE `items` (\n  `id` INT NOT NULL AUTO_INCREMENT ,\n  `name` TEXT NOT NULL,\n  `body` TEXT NOT NULL,\n  PRIMARY KEY ( `id` )\n)\n<\/code><\/pre>\n<p>name\u306f\u6295\u7a3f\u8005\u540d\u3001body\u306f\u672c\u6587\u3002<\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210<\/p>\n<p>C:\\rails\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\nC:\\rails\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u3066\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre><code>rails bbs\n<\/code><\/pre>\n<p>C:\\rails\\bbs\\config\\database.yml\u306edatabase\u306e\u9805\u76ee\u3092bbs\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre><code>development:\n  adapter: mysql\n  database: bbs\n  host: localhost\n  username: root\n  password: \n\ntest:\n  adapter: mysql\n  database: bbs\n  host: localhost\n  username: root\n  password:\n\nproduction:\n  adapter: mysql\n  database: bbs\n  host: localhost\n  username: root\n  password:\n<\/code><\/pre>\n<p>\u30e2\u30c7\u30eb\u3068\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre><code>ruby script\/generate model Item\n\nruby script\/generate controller item\n<\/code><\/pre>\n<p>\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0<\/p>\n<p>C:\\rails\\bbs\\app\\views\\item\\index.rhtml \u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\nindex.rhtml\u3067\u306f\u3001\u6295\u7a3f\u3055\u308c\u305f\u5185\u5bb9\u304c\u914d\u5217\u3067 @items \u306b\u5165\u308a\u3001 @items.each do \uff5e end \u3067\u3001\u6295\u7a3f\u5185\u5bb9\u3092\u51fa\u529b\u3059\u308b\u3002<br \/>\n\u30d5\u30a9\u30fc\u30e0\u3067\u5165\u529b\u3055\u308c\u305f\u5185\u5bb9\u306f\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e add_item \u30e1\u30bd\u30c3\u30c9\u3067\u51e6\u7406\u3092\u3059\u308b\u3002<\/p>\n<pre><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"&gt;\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"ja-JP\" lang=\"ja-JP\"&gt;\n&lt;head&gt;\n  &lt;title&gt;\u4e00\u884c\u63b2\u793a\u677f&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;h1&gt;\u4e00\u884c\u63b2\u793a\u677f&lt;\/h1&gt;\n  &lt;dl&gt;\n&lt;% @items.each do |@item| %&gt;\n    &lt;dt&gt;&lt;%=h @item.name %&gt;&lt;\/dt&gt;\n    &lt;dd&gt;&lt;%=h @item.body %&gt;&lt;\/dd&gt;\n&lt;% end %&gt;\n  &lt;\/dl&gt;\n  &lt;hr \/&gt;\n  &lt;%= form_tag :action=&gt;\"add_item\" %&gt;\n    \u540d\u524d:&lt;%= text_field(\"new_item\", \"name\", \"size\"=&gt;10) %&gt;&lt;br \/&gt;\n    \u672c\u6587:&lt;%= text_field(\"new_item\", \"body\", \"size\"=&gt;60) %&gt;&lt;br \/&gt;\n    &lt;input type=\"submit\" value=\"Add\" \/&gt;\n  &lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<p>C:\\rails\\bbs\\app\\controllers\\item_controller.rb \u3092\u958b\u304f\u3002<\/p>\n<pre><code>class ItemController &lt; ApplicationController\n\n  def index\n    @items = Item.find_all\n  end\n\n  def add_item\n    item = Item.new\n    item.attributes = @params[\"new_item\"]\n    if item.save\n      redirect_to(:action =&gt; \"index\")\n    else\n      render_text \"Couldn't add new item\"\n    end\n  end\nend\n<\/code><\/pre>\n<p>WEBrick \u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3059\u308b\u3002<\/p>\n<pre><code>ruby script\/server\n<\/code><\/pre>\n<p><a href=\"http:\/\/localhost:3000\/item\/\">http:\/\/localhost:3000\/item\/<\/a>\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002<br \/>\n\u63b2\u793a\u677f\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u3001\u6210\u529f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2007\u5e744\u670829\u65e5\u8ffd\u8a18\uff1aRuby on Rails 1.2\u5bfe\u5fdc\u7248\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002 Ruby on Rails\u306e\u7df4\u7fd2\u306b\u3001\u7c21\u5358\u306a\u63b2\u793a\u677f\u3092\u4f5c\u6210\u3057\u3066\u307f\u308b\u3002 \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4f5c\u6210 MySQL\u3092\u4f7f\u7528\u3057\u3066\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210 &#8230;<\/p>\n<p><a href=\"https:\/\/www.gesource.jp\/weblog\/?p=12\" class=\"more-link\">Continue reading &lsquo;Ruby on Rails\u3067\u4e00\u884c\u63b2\u793a\u677f\u3092\u4f5c\u6210\u3059\u308b&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[142,70],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-ruby","tag-ruby","tag-ruby-on-rails"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}