{"id":9275,"date":"2020-01-19T23:28:18","date_gmt":"2020-01-19T14:28:18","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=9275"},"modified":"2023-05-27T22:48:47","modified_gmt":"2023-05-27T13:48:47","slug":"%e3%80%90ruby-on-rails%e3%80%91activerecord%e3%81%ae%e5%9f%ba%e6%9c%ac%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%ef%bc%88save%e3%80%81create%e7%ad%89%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=9275","title":{"rendered":"\u3010Ruby on Rails\u3011ActiveRecord\u306e\u30e1\u30bd\u30c3\u30c9\u307e\u3068\u3081\uff08save\u3001create\u7b49\uff09\u3001\u7ba1\u7406\u30b3\u30de\u30f3\u30c9(rails xxx)\u3001hirb"},"content":{"rendered":"<h2>new<\/h2>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3060\u3051\u306a\u306e\u3067\u4fdd\u5b58\u3082\u3057\u305f\u3044\u5834\u5408\u306fsave\u3082\u4f75\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<h3>\u7528\u9014<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u306b\u4e00\u6642\u7684\u306b\u4fdd\u5b58\u3057\u3066\u304a\u3044\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30c1\u30a7\u30c3\u30af\u306b\u901a\u904e\u3057\u305f\u3089\u4fdd\u5b58\u3059\u308b\u3002\u901a\u904e\u3057\u306a\u304b\u3063\u305f\u3089\u767b\u9332\u753b\u9762\u306b\u623b\u3059<\/strong><\/span>\u3068\u3044\u3046\u3088\u3046\u306a\u7528\u9014\u3067\u4f7f\u3046\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">@user = User.new<\/pre>\n<h3>\u5b9f\u884c\u4f8b<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5068\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210.png\" alt=\"\" width=\"522\" height=\"38\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210.png 522w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210-300x22.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/p>\n<p>\u307e\u3060\u3001\u3053\u306e\u6642\u70b9\u3067\u306f\u7a7a\u306e\u4eee\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u3067\u304d\u305f\u3060\u3051\u3067\u3059\u3002<\/p>\n<h3>\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/h3>\n<h4>\u69cb\u6587<\/h4>\n<pre class=\"lang:default decode:true\">\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306e\u5909\u6570\u540d.\u30ab\u30e9\u30e0\u540d=\u5024<\/pre>\n<h4>\u5b9f\u884c\u4f8b<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5069\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u306b\u30c7\u30fc\u30bf\u3092\u8a2d\u5b9a.png\" alt=\"\" width=\"275\" height=\"82\" \/><\/p>\n<h2>create<\/h2>\n<p>new + save\u3092\u3057\u307e\u3059\u3002\u3064\u307e\u308a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u305d\u306e\u307e\u307eDB\u306b\u4fdd\u5b58\u3059\u308b\u306e\u3067\u3059\u3050\u306b\u30ec\u30b3\u30fc\u30c9\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9 \u3067\u3059\u3002\u623b\u308a\u5024\u306f\u4fdd\u5b58\u306b\u6210\u529f\u3057\u3066\u3082\u5931\u6557\u3057\u3066\u3082\u30e2\u30c7\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u306e\u3067\u3001new + save\u306e\u3088\u3046\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u6210\u529f\u3057\u305f\u3089\u4fdd\u5b58\u3001\u5931\u6557\u3057\u305f\u3089\u4fdd\u5b58\u3057\u306a\u3044\u3068\u3044\u3046\u5206\u5c90\u51e6\u7406\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u306e\u3067\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<h3>\u7528\u9014<\/h3>\n<p>\u5b9f\u52d9\u3067\u306f\u3042\u307e\u308a\u4f7f\u3046\u3053\u3068\u304c\u306a\u3044\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<span style=\"color: #ff0000;\"><strong>Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u3084seed\u3068\u304b\u3067\u3067\u624b\u65e9\u304f\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u305f\u3044\u5834\u5408\u3068\u304b\u306b\u4f7f\u3046\u6a5f\u4f1a\u304c\u591a\u3044<\/strong><\/span>\u3088\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<h2>save<\/h2>\n<p>DB\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u6210\u529f\u3057\u305f\u5834\u5408\u306f\u300ctrue\u300d\u3001\u5931\u6557\u3057\u305f\u5834\u5408\u306f\u300c<span class=\"s1\">false<\/span>\u300d\u304c\u8fd4\u308b\u3002<\/p>\n<ul>\n<li>\u3069\u3061\u3089\u3082\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u51e6\u7406\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/li>\n<li><span style=\"color: #ff0000;\"><strong>\u300c\u30e2\u30c7\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8.errors\u300d<\/strong><\/span>\u3092\u901a\u3058\u3066\u691c\u8a3c\u30a8\u30e9\u30fc\u5185\u5bb9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n<h3>errors<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>\u300cActiveModel::Errors\u300d<\/strong><\/span>\u3068\u3044\u3046\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n<h4>\u30e2\u30c7\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8.errors.full_message<\/h4>\n<p>\u691c\u8a3c\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u5185\u5bb9\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u69cb\u6587<\/h3>\n<p>\u4e0b\u8a18\u306e\u69cb\u6587\u3092\u4f7f\u7528\u3059\u308c\u3070\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306e\u5909\u6570\u540d.save<\/pre>\n<h4>\u5b9f\u884c\u4f8b<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5070\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/save_\u5b9f\u884c\u7d50\u679c.png\" alt=\"\" width=\"640\" height=\"129\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/save_\u5b9f\u884c\u7d50\u679c.png 640w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/save_\u5b9f\u884c\u7d50\u679c-300x60.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h4>\u7528\u9014<\/h4>\n<ul>\n<li>DB\u306b\u4fdd\u5b58\u3057\u305f\u5834\u5408\u306b\u5206\u5c90\u51e6\u7406\u3092\u884c\u305f\u5834\u5408\u306b\u4f7f\u3046\u3002<\/li>\n<li>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u304c\u3042\u308a\u5f97\u308b\u5834\u5408\u306f\u3053\u3061\u3089\u3092\u4f7f\u3046\u3002<\/li>\n<\/ul>\n<p>\u30c7\u30fc\u30bf\u3092\u8a2d\u5b9a\u3057\u305f\u3060\u3051\u3067\u306f\u307e\u3060\u3001\u30ec\u30b3\u30fc\u30c9\u81ea\u4f53\u304c\u30c6\u30fc\u30d6\u30eb\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<h3>\u767b\u9332\u7d50\u679c\u306e\u78ba\u8a8d<\/h3>\n<p>\u767b\u9332\u3057\u305fid\u3067\u691c\u7d22\u3059\u308b\u3068\u3001\u767b\u9332\u3057\u305f\u5185\u5bb9\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5071\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/rails_\u767b\u9332\u7d50\u679c\u78ba\u8a8d.png\" alt=\"\" width=\"642\" height=\"93\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/rails_\u767b\u9332\u7d50\u679c\u78ba\u8a8d.png 642w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/rails_\u767b\u9332\u7d50\u679c\u78ba\u8a8d-300x43.png 300w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><\/p>\n<h3>save!<\/h3>\n<p>\u30fb<span class=\"s1\">\u5931\u6557\u3057\u305f\u5834\u5408\u306f\u300c<\/span>ActiveRecord::RecordInvalid<span class=\"s1\">\u300d\u3092\u767a\u751f\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u3001<\/span>rescue<span class=\"s1\">\u3067\u6551\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3002\uff08\u305f\u3060\u3001\u57fa\u672c\u7684\u306bRails\u304c\u81ea\u52d5\u3067rescue\u3092\u884c\u3063\u3066\u304f\u308c\u3066\u958b\u767a\u8005\u81ea\u8eab\u306frescue\u3092\u66f8\u304b\u306a\u3044\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u4f7f\u3046\u30b1\u30fc\u30b9\u306f\u975e\u5e38\u306b\u5c11\u306a\u3044\u3067\u3059\u3002\uff09<\/span><\/p>\n<h4>\u7528\u9014<\/h4>\n<ul>\n<li class=\"p1\">\u4f8b\u5916\u3092\u30c8\u30ea\u30ac\u30fc\u306b\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u3055\u305b\u308b\u5834\u5408\u306b\u4f7f\u3046\u3002\uff08\u4e3b\u306a\u5834\u9762\u3068\u3057\u3066\u306fTransaction\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308a\u5927\u91cf\u30c7\u30fc\u30bf\u767b\u9332\u51e6\u7406\u3068\u304b\u3092\u884c\u3046\u5834\u5408\uff09<\/li>\n<\/ul>\n<h2>\u30ec\u30b3\u30fc\u30c9\u62bd\u51fa\u7cfb\u30e1\u30bd\u30c3\u30c9<\/h2>\n<h3>\u30c6\u30fc\u30d6\u30eb\u306b\u683c\u7d0d\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u5168\u3066\u53d6\u308a\u51fa\u3059\u3002<\/h3>\n<p>\u4e0b\u8a18\u306e\u69cb\u6587\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u540d.all<\/pre>\n<h4>\u5b9f\u884c\u4f8b<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5062\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u3092\u5168\u3066\u62bd\u51fa.png\" alt=\"\" width=\"641\" height=\"112\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u3092\u5168\u3066\u62bd\u51fa.png 641w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u3092\u5168\u3066\u62bd\u51fa-300x52.png 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/p>\n<h3>ID\u3092\u6307\u5b9a\u3057\u3066\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u308a\u51fa\u3059\u3002<\/h3>\n<p>\u4e0b\u8a18\u306e\u69cb\u6587\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u540d.find(\u8a72\u5f53\u30ec\u30b3\u30fc\u30c9\u306eid)<\/pre>\n<h4>\u5b9f\u884c\u4f8b<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5063\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/ID\u3092\u6307\u5b9a\u3057\u3066\u691c\u7d22.png\" alt=\"\" width=\"657\" height=\"253\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/ID\u3092\u6307\u5b9a\u3057\u3066\u691c\u7d22.png 657w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/ID\u3092\u6307\u5b9a\u3057\u3066\u691c\u7d22-300x116.png 300w\" sizes=\"(max-width: 657px) 100vw, 657px\" \/><\/p>\n<p>\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306b\u306f\u3001ID\u5217\u306f\u3001\u5fc5\u9808\u3067\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u300cUser.all\u300d<\/strong><\/span>\u30b3\u30de\u30f3\u30c9\u3067\u78ba\u8a8d\u3057\u3066\u3001\u305d\u306eID\u3092\u5143\u306b<span style=\"color: #ff0000;\"><strong>\u300cUser.find\u300d<\/strong><\/span>\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308c\u3070\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30ec\u30b3\u30fc\u30c9\u66f4\u65b0\u7cfb\u30e1\u30bd\u30c3\u30c9<\/h2>\n<p>\u6d41\u308c\u3068\u3057\u3066\u306f\u3001\u767b\u9332\u3068\u305d\u308c\u307b\u3069\u9055\u3044\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h3>update<\/h3>\n<p>\u5909\u66f4\u5185\u5bb9\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u66f4\u65b0\u3092\u884c\u3046\u3001save\u3084save!\u30e1\u30bd\u30c3\u30c9\u3092\u66f4\u65b0\u7528\u306b\u4fbf\u5229\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u767b\u9332\u6642\u306f\u691c\u8a3c\u3092\u884c\u3046\u3002<\/p>\n<h3>update!<\/h3>\n<p>\u5909\u66f4\u5185\u5bb9\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u66f4\u65b0\u3092\u884c\u3046\u3001save\u3084save!\u30e1\u30bd\u30c3\u30c9\u3092\u66f4\u65b0\u7528\u306b\u4fbf\u5229\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u767b\u9332\u6642\u306f\u691c\u8a3c\u3092\u884c\u3046\u3002<\/p>\n<h3>update_attributes<\/h3>\n<p>\u5909\u66f4\u5185\u5bb9\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u66f4\u65b0\u3092\u884c\u3046\u3001save\u3084save!\u30e1\u30bd\u30c3\u30c9\u3092\u66f4\u65b0\u7528\u306b\u4fbf\u5229\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u767b\u9332\u6642\u306f\u691c\u8a3c\u3092\u884c\u3046\u3002<\/p>\n<h3>update_attributes!<\/h3>\n<p>\u5909\u66f4\u5185\u5bb9\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u66f4\u65b0\u3092\u884c\u3046\u3001save\u3084save!\u30e1\u30bd\u30c3\u30c9\u3092\u66f4\u65b0\u7528\u306b\u4fbf\u5229\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u767b\u9332\u6642\u306f\u691c\u8a3c\u3092\u884c\u3046\u3002<\/p>\n<h3>update_attribute<\/h3>\n<p>1\u3064\u306e\u5c5e\u6027\u306e\u5909\u66f4\u3092\u884c\u3046\u304c\u767b\u9332\u6642\u306b\u691c\u8a3c\u3092\u884c\u308f\u306a\u3044\u3002<\/p>\n<h3>update_column<\/h3>\n<p>\u5909\u66f4\u5185\u5bb9\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u66f4\u65b0\u3092\u884c\u3046\u304c\u3001\u691c\u8a3c\u3084\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306f\u884c\u308f\u306a\u3044\u3002\u66f4\u65b0SQL\u3092\u76f4\u63a5\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<h3>update_columns<\/h3>\n<p>\u5909\u66f4\u5185\u5bb9\u3092\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u66f4\u65b0\u3092\u884c\u3046\u304c\u3001\u691c\u8a3c\u3084\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306f\u884c\u308f\u306a\u3044\u3002\u66f4\u65b0SQL\u3092\u76f4\u63a5\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<h3>update_all<\/h3>\n<p>\u66f4\u65b0SQL\u3092\u5b9f\u884c\u3059\u308b\u3002\u691c\u8a3c\u3084\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306f\u884c\u308f\u306a\u3044\u3002<\/p>\n<h3>\u76f4\u63a5\u66f4\u65b0\uff1a\u5909\u6570\u3078\u767b\u9332\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u3092\u683c\u7d0d<\/h3>\n<pre class=\"lang:default decode:true\">\u5909\u6570\u540d = \u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u540d.find(\u8a72\u5f53\u306eID)<\/pre>\n<h4>\u5b9f\u884c\u7d50\u679c<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5073\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u66f4\u65b0\u7cfb_\u5909\u6570\u3078\u683c\u7d0d.png\" alt=\"\" width=\"642\" height=\"94\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u66f4\u65b0\u7cfb_\u5909\u6570\u3078\u683c\u7d0d.png 642w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u66f4\u65b0\u7cfb_\u5909\u6570\u3078\u683c\u7d0d-300x44.png 300w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><\/p>\n<h3>\u30ec\u30b3\u30fc\u30c9\u5185\u5bb9\u3092\u66f4\u65b0\u3059\u308b\u3002<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5074\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u66f4\u65b0\u7cfb_\u30ec\u30b3\u30fc\u30c9\u306e\u66f4\u65b0.png\" alt=\"\" width=\"270\" height=\"41\" \/><\/p>\n<h3>\u4fdd\u5b58\u53ca\u3073\u3001\u78ba\u8a8d<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5075\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u4fdd\u5b58\u53ca\u3073\u3001\u78ba\u8a8d.png\" alt=\"\" width=\"639\" height=\"238\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u4fdd\u5b58\u53ca\u3073\u3001\u78ba\u8a8d.png 639w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u4fdd\u5b58\u53ca\u3073\u3001\u78ba\u8a8d-300x112.png 300w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/p>\n<h2>\u524a\u9664\u7cfb\u30e1\u30bd\u30c3\u30c9<\/h2>\n<h3>\u5909\u6570\u306b\u5024\u3092\u683c\u7d0d<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5078\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u524a\u9664\u7cfb\uff3f\u5909\u6570\u306b\u5024\u3092\u683c\u7d0d.png\" alt=\"\" width=\"640\" height=\"97\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u524a\u9664\u7cfb\uff3f\u5909\u6570\u306b\u5024\u3092\u683c\u7d0d.png 640w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u524a\u9664\u7cfb\uff3f\u5909\u6570\u306b\u5024\u3092\u683c\u7d0d-300x45.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h3>\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3001\u78ba\u8a8d<\/h3>\n<p>\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\u306b\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u300cdestroy\u30e1\u30bd\u30c3\u30c9\u300d<\/strong><\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5079\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\u3001\u78ba\u8a8d.png\" alt=\"\" width=\"645\" height=\"220\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\u3001\u78ba\u8a8d.png 645w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\u3001\u78ba\u8a8d-300x102.png 300w\" sizes=\"(max-width: 645px) 100vw, 645px\" \/><\/p>\n<h2>\u7ba1\u7406\u7cfb\u30b3\u30de\u30f3\u30c9<\/h2>\n<h3>rails -v<\/h3>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308bRails\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n<h3>rails s<\/h3>\n<p>\u4f5c\u6210\u3057\u305fRails\u30a2\u30d7\u30ea\u3092\u8d77\u52d5\u3059\u308b\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u958b\u767a(development)\u304c\u8d77\u52d5\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h4>rails s -e (test\/production)<\/h4>\n<p>\u30c6\u30b9\u30c8\u74b0\u5883\u3084\u672c\u756a\u74b0\u5883\u3092\u8d77\u52d5\u3059\u308b\u3002<\/p>\n<h3>rails routes<\/h3>\n<p>Rails\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u60c5\u5831\u3092\u51fa\u529b\u3059\u308b\u3002<\/p>\n<h3>rails c<\/h3>\n<p>irb\u304c\u8d77\u52d5\u3057\u3066Rails\u306e\u30b3\u30fc\u30c9\u3092\u5bfe\u8a71\u7684\u306b\u8a66\u3059\u3053\u3068\u304c\u53ef\u80fd\u3002<\/p>\n<h3>rails c -s<\/h3>\n<p>irb\u304c\u8d77\u52d5\u3057\u3066Rails\u306e\u30b3\u30fc\u30c9\u3092\u5bfe\u8a71\u7684\u306b\u8a66\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u306a\u304a\u3001<span style=\"color: #ff0000;\"><strong>DB\u3092\u3044\u3058\u3063\u3066\u3082\u7d42\u4e86\u3059\u308b\u3068\u304d\u306b\u81ea\u52d5\u3067\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u30c6\u30b9\u30c8\u7684\u306b\u30b3\u30fc\u30c9\u3092\u52d5\u304b\u3057\u305f\u3044\u969b\u306b\u975e\u5e38\u306b\u4fbf\u5229<\/strong><\/span>\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<h2>\u30bd\u30fc\u30b9\u81ea\u52d5\u751f\u6210\u7cfb\u30b3\u30de\u30f3\u30c9<\/h2>\n<h3>rails new \u30a2\u30d7\u30ea\u540d<\/h3>\n<p>Rails\u30a2\u30d7\u30ea\u306b\u5fc5\u8981\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u65b0\u898f\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<h3 class=\"p1\"><span class=\"s1\">rails _X.X.X(Rails\u306e\u30d0\u30fc\u30b8\u30e7\u30f3)_ new \u30a2\u30d7\u30ea\u540d<\/span><\/h3>\n<p>Rails\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3066\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<h3 class=\"p1\"><span class=\"s1\">rails new \u30a2\u30d7\u30ea\u540d -d postgresql<\/span><\/h3>\n<p>postgresql\u3092\u4f7f\u7528\u3057\u3066\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<h3>rails g controller [\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u540d] [\u30a2\u30af\u30b7\u30e7\u30f3\u540d](\u7701\u7565\u53ef\u80fd)<\/h3>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u3002<\/p>\n<h3><span class=\"crayon-i\">rails<\/span> <span class=\"crayon-i\">g<\/span> <span class=\"crayon-i\">scaffold<\/span> \u30ea\u30bd\u30fc\u30b9\u540d \u30ab\u30e9\u30e0\u540d<span class=\"crayon-cn\">1<\/span><span class=\"crayon-o\">:<\/span>\u30c7\u30fc\u30bf\u578b<span class=\"crayon-cn\">1<\/span> \u30ab\u30e9\u30e0\u540d<span class=\"crayon-cn\">2<\/span><span class=\"crayon-o\">:<\/span>\u30c7\u30fc\u30bf\u578b<span class=\"crayon-cn\">2<\/span><\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u30c7\u30fc\u30bf\u3092\u5143\u306b\u3057\u3066\u30a2\u30d7\u30ea\u306e\u96db\u5f62\u3092\u4f5c\u6210\u3059\u308b\u30b3\u30de\u30f3\u30c9<\/p>\n<h3>rails assets:precompile<\/h3>\n<p>Rails\u306e\u30d7\u30ea\u30b3\u30f3\u30d1\u30a4\u30eb\u3092\u3059\u308b\u30b3\u30de\u30f3\u30c9<\/p>\n<h2>DB\u7cfb\u30b3\u30de\u30f3\u30c9<\/h2>\n<h3>rails g model \u30e2\u30c7\u30eb\u540d \u30ab\u30e9\u30e0\u540d1:\u30c7\u30fc\u30bf\u578b1 \u30ab\u30e9\u30e02:\u30c7\u30fc\u30bf\u578b2<\/h3>\n<p>\u7a7a\u306e\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u304a\u3088\u3073\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u305f\u3060\u3051\u3067\u306f<span style=\"color: #ff0000;\"><strong>\u30c6\u30fc\u30d6\u30eb\u306f\u4f5c\u6210\u3055\u308c\u306a\u3044\u3002<\/strong><\/span><\/p>\n<h3><span class=\"crayon-e\">rails <\/span><span class=\"crayon-v\">db<\/span><span class=\"crayon-o\">:<\/span><span class=\"crayon-v\">migrate<\/span><\/h3>\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u7528\u30b3\u30de\u30f3\u30c9\u3001\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b<span style=\"color: #ff0000;\"><strong>\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<\/strong><\/span><\/p>\n<h3>rails dbconsole<\/h3>\n<p>\u300cconfig\/database.yml\u300d\u3067\u5b9a\u7fa9\u3057\u305f\u63a5\u7d9a\u60c5\u5831\u306b\u5f93\u3063\u3066\u3001Rails\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u63a5\u7d9a\u3059\u308b\u3002<\/p>\n<h3>rails:db:fixtures:load<\/h3>\n<p>fixtures\uff08\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\uff09\u3092\u958b\u767a\u7528\u306eDB\u306b\u53d6\u308a\u8fbc\u3080\u3002<\/p>\n<h3 class=\"p1\"><span class=\"s1\">rails db:drop:all DISABLE_DATABASE_ENVIRONMENT_CHECK=1<\/span><\/h3>\n<p>\u4f5c\u6210\u6e08\u307f\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u5168\u3066\u524a\u9664\u3059\u308b\u3002<\/p>\n<h3 class=\"p1\"><span class=\"s1\">rails db:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1<\/span><\/h3>\n<p>\u73fe\u5728\u306e\u30c6\u30fc\u30d6\u30eb\u30ec\u30a4\u30a2\u30a6\u30c8\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u518d\u4f5c\u6210\u3059\u308b\u3002\u305d\u306e\u5f8c\u518d\u5ea6\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u633f\u5165\u3057\u305f\u3044\u5834\u5408\u306f<span style=\"color: #ff0000;\"><strong>\u300crails:db:fixtures:load\u300d<\/strong><\/span>\u3092\u5b9f\u65bd\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u524a\u9664\u7cfb\u30b3\u30de\u30f3\u30c9<\/h2>\n<h3>rails destroy controller \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u540d<\/h3>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u95a2\u9023\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b\u3002<\/p>\n<h2>\u30c6\u30fc\u30d6\u30eb\u30c7\u30fc\u30bf\u3092\u898b\u3084\u3059\u304f\u3059\u308bGem\u306e\u300chirb\u300d<\/h2>\n<h3>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"lang:default decode:true\"># \u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u7d50\u679c\u3092\u8868\u306b\u3059\u308b\r\ngem 'hirb', '~&gt; 0.7.3'\r\n# \u30b3\u30f3\u30bd\u30fc\u30eb\u6587\u5b57\u5217\u88dc\u6b63\r\ngem 'hirb-unicode-steakknife', '~&gt; 0.0.9'<\/pre>\n<p>hirb\u306b\u52a0\u3048\u3066\u65e5\u672c\u8a9e\u5bfe\u5fdc\u3055\u305b\u308b\u305f\u3081\u306b\u300chirb-unicode-steakknife\u300d\u3068\u8a00\u3046Gem\u3082\u4f75\u305b\u3066\u8ffd\u52a0\u3059\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h3>\u8a2d\u5b9a<\/h3>\n<p>.irbrc\u3068\u8a00\u3046\u30d5\u30a1\u30a4\u30eb\u3092Rails\u30a2\u30d7\u30ea\u76f4\u4e0b\u306b\u4f5c\u6210\u3057\u3066Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u8d77\u52d5\u6642\u306b\u81ea\u52d5\u3067\u8aad\u307f\u8fbc\u307e\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002(Hirb.enable\u306fhirb\u3092\u6709\u52b9\u5316\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3067Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u8d77\u52d5\u3059\u308b\u305f\u3073\u306b\u6bce\u56de\u3084\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u3057\u3066\u4ed5\u8fbc\u307f\u307e\u3059\u3002\uff09<\/p>\n<pre class=\"lang:default decode:true\"># \u30b3\u30f3\u30bd\u30fc\u30eb\u8d77\u52d5\u6642\r\nif defined? Rails::Console\r\n  # Hirb.enable\u306e\u6709\u52b9\u5316\r\n  Hirb.enable if defined? Hirb\r\nend<\/pre>\n<h3>\u5b9f\u884c<\/h3>\n<p>Rails\u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u3067Hirb\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<h4>\u6709\u52b9\u78ba\u8a8d<\/h4>\n<p>\u3044\u304b\u304ctrue\u304c\u8fd4\u3063\u3066\u304d\u305f\u3089Hirb\u304c\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">Hirb::View.enabled?<\/pre>\n<h4>\u4e8c\u6b21\u5143\u914d\u5217\u3092\u8868\u306b\u3059\u308b\u3002<\/h4>\n<pre class=\"lang:default decode:true\">puts Hirb::Helpers::Table.render [[3,2], [2,3]]<\/pre>\n<h4>\u30cf\u30c3\u30b7\u30e5\u3092\u8868\u306b\u3059\u308b\u3002<\/h4>\n<pre class=\"lang:default decode:true \">puts Hirb::Helpers::Table.render [{:age=&gt;10, :name=&gt;\"\u592a\u90ce\"}, {:age=&gt;80, :name=&gt;\"\u6b21\u90ce\"}]<\/pre>\n","protected":false},"excerpt":{"rendered":"new \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3060\u3051\u306a\u306e\u3067\u4fdd\u5b58\u3082\u3057\u305f\u3044\u5834\u5408\u306fsave\u3082\u4f75\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002 \u7528\u9014 \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u306b\u4e00\u6642\u7684\u306b\u4fdd\u5b58\u3057\u3066\u304a\u3044\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30c1\u30a7\u30c3\u30af\u306b\u901a\u904e\u3057\u305f\u3089\u4fdd\u5b58\u3059\u308b\u3002\u901a\u904e\u3057\u306a\u304b\u3063\u305f\u3089\u767b\u9332\u753b\u9762\u306b\u623b\u3059\u3068\u3044\u3046\u3088\u3046 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9275"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9275"}],"version-history":[{"count":22,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9275\/revisions"}],"predecessor-version":[{"id":20515,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9275\/revisions\/20515"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9275"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}