{"id":8436,"date":"2022-08-04T06:03:16","date_gmt":"2022-08-03T21:03:16","guid":{"rendered":"https:\/\/yumishin.com\/?p=8436"},"modified":"2022-08-04T06:03:16","modified_gmt":"2022-08-03T21:03:16","slug":"download-rails","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=8436","title":{"rendered":"\u3010Rails\u3011\u30e2\u30c7\u30eb\u3084\u95a2\u9023\u3059\u308b\u60c5\u5831\u3092Json\u5f62\u5f0f\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<h2 id=\"i-0\">\u3010Rails\u3011\u30e2\u30c7\u30eb\u3084\u95a2\u9023\u3059\u308b\u60c5\u5831\u3092Json\u5f62\u5f0f\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5<\/h2>\n<h3 id=\"i-1\">\u5168\u4f53\u306e\u6d41\u308c<\/h3>\n<ul>\n<li>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u7528\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u4f5c\u308b<\/li>\n<li>view\u5074\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u7528\u30dc\u30bf\u30f3\u3092\u4f5c\u308b<\/li>\n<li>controller\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u7528\u306e\u51e6\u7406\u3092\u304b\u304f<\/li>\n<\/ul>\n<h3 id=\"i-2\">\u5177\u4f53\u4f8b<\/h3>\n<p>\u4f8b\u3048\u3070\u3001\u8a3c\u660e\u66f8\u95a2\u9023\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u3044\u3068\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u4f5c\u3063\u3066\u3042\u3052\u307e\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>resources :certificates, only: %i[edit update] do\n  member do\n    get :download_setting_info\n  end\nend<\/code><\/pre>\n<\/div>\n<p>\u7d9a\u3044\u3066\u3001view\u5074\u3067\u30dc\u30bf\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u4e0a\u3067\u8a2d\u5b9a\u3057\u305f\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u98db\u3079\u308b\u3088\u3046\u306b\u3057\u3066\u3042\u3052\u307e\u3059\u3002<\/p>\n<p>method: :get\u3092\u3064\u3051\u3066\u304a\u304b\u306a\u3044\u3068\u3001default\u3067post\u3078\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>&lt;div class=\"nav__actions\"&gt;\n\u3000\u3000\u3000&lt;div class=\"nav__item\"&gt;&lt;%= button_to t(\".download_setting_info\"), download_setting_info_certificate_path(@certificate.id), { method: :get, class: \"btn btn--primary\" } %&gt;&lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<\/div>\n<p>\u3042\u3068\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306e\u51e6\u7406\u3067\u3059\u3002<\/p>\n<p>\u8a3c\u660e\u66f8\u985e\u306e\u540d\u524d\u306a\u3069\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u8868\u793a\u3057\u305f\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u66f8\u304d\u307e\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>def download_setting_info\n\u3000\u3000@certificate = Certificate.find(params[:id])\n\u3000\u3000setting_info_hash = {\n\u3000\u3000\u3000\u3000\"DeviceId\": @certificate.device.device_id,\n\u3000\u3000\u3000\u3000\"PublicKey\": @certificate.public_key,\n\u3000\u3000\u3000\u3000\"PrivateKey\": @certificate.private_key,\n\u3000\u3000}\n\u3000\u3000setting_info_json = JSON.pretty_generate(setting_info_hash)\n\u3000\u3000send_data(setting_info_json, type: 'application\/json', filename: \"#{@certificate.device.aws_iot_device_id}.json\")\nend<\/code><\/pre>\n<\/div>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u884c\u3051\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010Rails\u3011\u30e2\u30c7\u30eb\u3084\u95a2\u9023\u3059\u308b\u60c5\u5831\u3092Json\u5f62\u5f0f\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5 \u5168\u4f53\u306e\u6d41\u308c \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u7528\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u4f5c\u308b view\u5074\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u7528\u30dc\u30bf\u30f3\u3092\u4f5c\u308b controller\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u7528\u306e\u51e6\u7406\u3092\u304b\u304f \u5177\u4f53\u4f8b \u4f8b &#8230; <\/p>\n","protected":false},"author":1,"featured_media":8437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256],"tags":[],"class_list":{"0":"post-8436","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-it","8":"entry"},"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/8436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8436"}],"version-history":[{"count":1,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/8436\/revisions"}],"predecessor-version":[{"id":8438,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/8436\/revisions\/8438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/8437"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}