{"id":1565,"date":"2022-06-18T01:59:20","date_gmt":"2022-06-17T17:59:20","guid":{"rendered":"https:\/\/fromideatocreation.com\/?p=1130"},"modified":"2023-07-02T16:40:45","modified_gmt":"2023-07-02T08:40:45","slug":"rails-6-%e8%a3%a1%e8%a8%ad%e5%ae%9a%e7%92%b0%e5%a2%83%e8%ae%8a%e6%95%b8%e8%88%87%e6%86%91%e8%ad%89","status":"publish","type":"post","link":"https:\/\/fromideatocreation.com\/?p=1565","title":{"rendered":"Rails 6 \u88e1\u8a2d\u5b9a\u74b0\u5883\u8b8a\u6578\u8207\u6191\u8b49"},"content":{"rendered":"\n<p>\u61c9\u7528\u7a0b\u5f0f\u901a\u5e38\u4e2d\u6709\u5404\u7a2e\u5bc6\u78bc\u548c\u6191\u8b49\uff0c\u6211\u5011\u9700\u8981\u4f7f\u7528 API \u5bc6\u9470\u3001\u5bc6\u78bc\u7b49\u3002\u5c0d\u65bc\u9019\u4e9b\u6a5f\u5bc6\uff0c\u6211\u5011\u9700\u8981\u80fd\u5920\u65b9\u4fbf\u3001\u5b89\u5168\u5730\u7ba1\u7406\u6191\u8b49\u3002<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u65b0\u589e\/\u66f4\u65b0\u74b0\u5883\u8b8a\u6578\u8207\u6191\u8b49\uff08credentials\uff09<\/h2>\n\n\n\n<p>\u6211\u5011\u53ef\u4ee5\u901a\u904e\u57f7\u884c\u4ee5\u4e0b\u6307\u5b9a\u4f86\u7de8\u8f2f\u6191\u8b49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ EDITOR=vim rails credentials:edit<\/code><\/pre>\n\n\n\n<p>\u9019\u5c07\u6253\u958b vim \u7de8\u8f2f\u5668\uff0c\u5176\u4e2d\u5305\u542b\u6191\u8b49\u6587\u4ef6\u7684\u89e3\u5bc6\u7248\u672c\u3002<\/p>\n\n\n\n<p>\u6211\u5011\u53ef\u4ee5\u6dfb\u52a0 YAML \u683c\u5f0f\u7684\u65b0\u6191\u8b49\u3002 \u8b93\u6211\u5011\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff0c\u4fdd\u5b58\u66f4\u6539\u4e26\u9000\u51fa\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">aws:\n  access_key_id: 123\n  secret_access_key: 345\ngithub:\n  app_id: 123\n  app_secret: 345\n<\/code><\/pre>\n\n\n\n<p>\u7576\u6211\u5011\u4fdd\u5b58\u5b83\u6642\uff0c\u5b83\u6703\u4f7f\u7528\u76f8\u540c\u7684\u4e3b\u5bc6\u9470\u518d\u6b21\u52a0\u5bc6\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6c92\u6709\u8a2d\u7f6e\u9810\u8a2d\u7de8\u8f2f\u5668\u4e26\u4e14\u6211\u5011\u6c92\u6709\u6307\u5b9a\u7de8\u8f2f\u5668\uff0c\u90a3\u9ebc\u6211\u5011\u6703\u6536\u5230\u4ee5\u4e0b\u6d88\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ rails credentials:edit\nNo $EDITOR to open file in. Assign one like this:\n\nEDITOR=\"mate --wait\" bin\/rails credentials:edit\n\nFor editors that fork and exit immediately, it's important to pass a wait flag,\notherwise the credentials will be saved immediately with no chance to edit.<\/code><\/pre>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u8b80\u53d6\u6191\u8b49<\/h2>\n\n\n\n<p>\u6211\u5011\u73fe\u5728\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u65b9\u5f0f\u53d6\u5f97\u6191\u8b49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">&gt; Rails.application.credentials.config\n#=&gt; {:aws=&gt;{:access_key_id=&gt;\"123\", :secret_access_key=&gt;\"345\"}, :github=&gt;{:app_id=&gt;\"123\", :app_secret=&gt;\"345\"}}\n&gt; Rails.application.credentials.github\n#=&gt; {:app_id=&gt;\"123\", :app_secret=&gt;\"345\"}\n&gt; Rails.application.credentials.github[:app_id]\n#=&gt; \"123\"<\/code><\/pre>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728 Rails 6 \u88e1\u7ba1\u7406\u591a\u74b0\u5883\u8b8a\u6578\u3001\u6191\u8b49<\/h2>\n\n\n\n<p>\u8981\u70ba <code>production<\/code> \u74b0\u5883\u5efa\u7acb\u6191\u8b49\uff0c\u6211\u5011\u53ef\u4ee5\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ rails credentials:edit --environment production<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u547d\u4ee4\u57f7\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u7f3a\u5c11\uff0c\u5247\u5efa\u7acb <code>config\/credentials\/production.key<\/code>\u3002 \u4e0d\u8981\u5c07\u6b64\u6587\u4ef6\u63d0\u4ea4\u7d66 VCS\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u7f3a\u5c11\uff0c\u5247\u5efa\u7acb<code> config\/credentials\/production.yml.enc<\/code>\u3002 \u5c07\u6b64\u6587\u4ef6\u63d0\u4ea4\u5230 VCS\u3002<\/li>\n\n\n\n<li>\u5728\u9810\u8a2d\u7de8\u8f2f\u5668\u4e2d\u89e3\u5bc6\u4e26\u6253\u958b\u751f\u7522\u6191\u8b49\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>\u6211\u5011\u8207\u53ef\u4ee5\u9032\u884c\u751f\u7522\u90e8\u7f72\u7684\u6709\u9650\u5718\u968a\u6210\u54e1\u5171\u4eab production.key\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8b93\u6211\u5011\u6dfb\u52a0\u4ee5\u4e0b\u6191\u8b49\u4e26\u4fdd\u5b58\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">aws:\n  access_key_id: 1f3649fe-ebbd-11e9-81b4-2a2ae2dbcce4\n  secret_access_key: 203060d3a5456fa6cd2da3c958001440<\/code><\/pre>\n\n\n\n<p>\u540c\u6a23\uff0c\u6211\u5011\u53ef\u4ee5\u70ba\u4e0d\u540c\u7684\u74b0\u5883\uff08\u5982 staging\uff09\u5efa\u7acb\u6191\u8b49\u3002<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728 Rails \u88e1\u4f7f\u7528\u6191\u8b49<\/h2>\n\n\n\n<p>\u5c0d\u65bc\u4efb\u4f55\u74b0\u5883\uff0cRails \u90fd\u6703\u81ea\u52d5\u6aa2\u6e2c\u8981\u4f7f\u7528\u7684\u6191\u8b49\u96c6\u3002 \u7279\u5b9a\u65bc\u74b0\u5883\u7684\u6191\u64da\u5c07\u512a\u5148\u65bc\u5168\u5c40\u6191\u64da\u3002 \u5982\u679c\u5b58\u5728\u7279\u5b9a\u65bc\u74b0\u5883\u7684\u6191\u64da\uff0c\u5247\u5c07\u4f7f\u7528\u5b83\u5011\uff0c\u5426\u5247 Rails \u5c07\u9810\u8a2d\u4f7f\u7528\u5168\u5c40\u6191\u64da\u3002<\/p>\n\n\n\n<p>\u5c0d\u65bc development\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ rails c\n&gt; Rails.application.credentials.config\n#=&gt; {:aws=&gt;{:access_key_id=&gt;\"123\", :secret_access_key=&gt;\"345\"} }}\n&gt; Rails.application.credentials.aws[:access_key_id]\n#=&gt; \"123\"<\/code><\/pre>\n\n\n\n<p>\u5c0d\u65bc production\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ RAILS_ENV=production rails c\n&gt; Rails.application.credentials.config\n#=&gt; {:aws=&gt;{:access_key_id=&gt;\"1f3649fe-ebbd-11e9-81b4-2a2ae2dbcce4\", :secret_access_key=&gt;\"203060d3a5456fa6cd2da3c958001440\"}}\n&gt; Rails.application.credentials.aws[:access_key_id]\n#=&gt; \"1f3649fe-ebbd-11e9-81b4-2a2ae2dbcce4\"<\/code><\/pre>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c07\u52a0\u5bc6\u5bc6\u9470\u5132\u5b58\u5728\u74b0\u5883\u8b8a\u6578\u4e2d<\/h2>\n\n\n\n<p>\u6211\u5011\u9084\u53ef\u4ee5\u5728 <code>RAILS_MASTER_KEY<\/code> \u74b0\u5883\u8b8a\u6578\u4e2d\u8a2d\u7f6e\u52a0\u5bc6\u5bc6\u9470\u7684\u503c\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u8a2d\u7f6e\u4e86 <code>RAILS_MASTER_KEY<\/code>\uff0c\u6211\u5011\u4e0d\u9700\u8981\u5efa\u7acb <code>*.key<\/code> \u6587\u4ef6\u3002 Rails \u5c07\u81ea\u52d5\u6aa2\u6e2c\u6b64\u74b0\u5883\u8b8a\u91cf\u4e26\u4f7f\u7528\u5b83\u4f86\u52a0\u5bc6\/\u89e3\u5bc6\u6191\u8b49\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u74b0\u5883\u8b8a\u91cf\u53ef\u4ee5\u5728 Heroku \u6216\u985e\u4f3c\u5e73\u53f0\u4e0a\u4f7f\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\"># Setting master key on Heroku\nheroku config:set RAILS_MASTER_KEY=`cat config\/credentials\/production.key`<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u61c9\u7528\u7a0b\u5f0f\u901a\u5e38\u4e2d\u6709\u5404\u7a2e\u5bc6\u78bc\u548c\u6191\u8b49\uff0c\u6211\u5011\u9700\u8981\u4f7f\u7528 API \u5bc6\u9470\u3001\u5bc6\u78bc\u7b49\u3002\u5c0d\u65bc\u9019\u4e9b\u6a5f\u5bc6\uff0c\u6211\u5011\u9700\u8981\u80fd\u5920\u65b9\u4fbf\u3001\u5b89\u5168\u5730\u7ba1\u7406\u6191\u8b49\u3002<\/p>\n","protected":false},"author":1,"featured_media":642,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"qubely_global_settings":"","qubely_interactions":"","inline_featured_image":false,"_ti_tpc_template_sync":false,"_ti_tpc_template_id":"","footnotes":""},"categories":[105,106],"tags":[215,128],"class_list":["post-1565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-106","tag-credentials","tag-ruby-on-rails"],"acf":[],"aioseo_notices":[],"qubely_featured_image_url":{"full":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",1320,1323,false],"landscape":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",748,750,false],"portraits":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",319,320,false],"thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",150,150,false],"medium":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",300,300,false],"medium_large":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",640,641,false],"large":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",640,641,false],"1536x1536":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",1320,1323,false],"2048x2048":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",1320,1323,false],"qubely_landscape":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",748,750,false],"qubely_portrait":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",319,320,false],"qubely_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",100,100,false],"nazare_single_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",499,500,false],"nazare_post_card_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",480,481,false],"nazare_widget_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",100,100,false],"nazare_widget_first_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",206,206,false],"nazare_el_banner_left":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",603,604,false],"nazare_el_banner_right":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",494,495,false],"nazare_el_post_400x376":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",375,376,false],"nazare_el_post_520x460":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",459,460,false],"nazare_el_post_500x335":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",334,335,false],"nazare_el_post_500x300":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",299,300,false],"nazare_el_post_655x640":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",639,640,false],"nazare_el_post_500x290":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",289,290,false],"nazare_el_post_416x278":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",277,278,false],"nazare_el_post_480x425":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",424,425,false],"nazare_el_post_635x640":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",635,636,false],"nazare_el_post_305x177":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",177,177,false],"nazare_el_post_400x400":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",400,400,false],"nazare_el_post_400x360":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",359,360,false],"nazare_el_post_416x416":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",416,416,false],"nazare_el_post_485x430":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",429,430,false],"nazare_el_post_700x467":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",466,467,false],"nazare_el_post_1000x581":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",580,581,false],"nazare_post_1320x605":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",604,605,false],"nazare_post_705x565":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",564,565,false],"nazare_post_400x265":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",264,265,false],"nazare_el_post_1248x630":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",629,630,false],"woocommerce_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",300,300,false],"woocommerce_single":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",600,601,false],"woocommerce_gallery_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",100,100,false],"shop_catalog":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",300,300,false],"shop_single":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",600,601,false],"shop_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/04\/blog60.webp",100,100,false]},"qubely_author":{"display_name":"Wen","author_link":"https:\/\/fromideatocreation.com\/?author=1"},"qubely_comment":0,"qubely_category":"<a href=\"https:\/\/fromideatocreation.com\/?cat=105\" rel=\"category\">Ruby on Rails<\/a> <a href=\"https:\/\/fromideatocreation.com\/?cat=106\" rel=\"category\">\u6559\u5b78<\/a>","qubely_excerpt":"\u61c9\u7528\u7a0b\u5f0f\u901a\u5e38\u4e2d\u6709\u5404\u7a2e\u5bc6\u78bc\u548c\u6191\u8b49\uff0c\u6211\u5011\u9700\u8981\u4f7f\u7528 API \u5bc6\u9470\u3001\u5bc6\u78bc\u7b49\u3002\u5c0d\u65bc\u9019\u4e9b\u6a5f\u5bc6\uff0c\u6211\u5011\u9700\u8981\u80fd\u5920\u65b9\u4fbf\u3001\u5b89\u5168\u5730\u7ba1\u7406...","_links":{"self":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1565"}],"version-history":[{"count":1,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1565\/revisions"}],"predecessor-version":[{"id":1635,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1565\/revisions\/1635"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/media\/642"}],"wp:attachment":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}