{"id":9099,"date":"2020-03-11T13:55:48","date_gmt":"2020-03-11T08:25:48","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=9099"},"modified":"2021-09-15T17:38:59","modified_gmt":"2021-09-15T12:08:59","slug":"password-protected-zip-using-ruby-on-rails","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/","title":{"rendered":"Generating Password Protected Zip files using Ruby on Rails"},"content":{"rendered":"\n<p>This blog will guide you on how to create a Ruby on Rails application and add <a href=\"https:\/\/github.com\/rubyzip\/rubyzip#rubyzip\" target=\"_blank\" rel=\"noopener noreferrer\">rubyzip<\/a> which used to make zip files with Password Protection.<\/p>\n\n\n\n<p>Let\u2019s have a brief introduction about Password Protection using rubyzip. If you are familiar with rubyzip and Password Protection, then directly go to the Implementation section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Rubyzip?<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>It\u2019s a ruby gem (library) that is used to read and write zip files.<\/li><li>rubyzip provides you with the power of reading and writing zip files and also makes password-protected zip files.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why Rubyzip?<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Complete password protected reading and writing of zip files<\/li><li>rubyzip provides traditional password protection.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Requirements<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Ruby 1.9.2 or greater<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Technology Stack<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Technology: Ruby on Rails<\/li><li>Versions: ruby 2.5.1p57 &amp; rails 5.2.4<\/li><li>Git Repository:<a href=\"https:\/\/github.com\/jigarshah8055\/zipper\" target=\"_blank\" rel=\"noopener noreferrer\"> https:\/\/github.com\/jigarshah8055\/zipper<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Implementation<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Create a new rails app<\/li><\/ul>\n\n\n\n<p><code>$ rails new zipper --database=postgresql<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Now put below gem in the `Gemfile` as<\/li><\/ul>\n\n\n\n<p><code>gem 'rubyzip', '&gt;= 1.0.0'<\/code><\/p>\n\n\n\n<p><em><strong>Don\u2019t forget to bundle \ud83d\ude09<\/strong><\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Generate a controller with the `create` and `new` method<\/li><\/ul>\n\n\n\n<p><code>rails g controller zipping_folders new<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Simply set the root path to zipping_folders new method and make resource path for only create method in routes.rb<\/li><\/ul>\n\n\n\n<p><code>resources :zipping_folders, only: [:create]<\/code><br><code>root \u2018zipping_folders#new\u2019<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Now make a form in new.html.erb with one file tag to choose files and two input fields that define zip file name and password respectively.<\/li><\/ul>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/jigarshah8055\/3ad2b0c93f711626fcc21e5a43c3fa3c.js\"><\/script><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You have to write below code in zipping_folders_controller.rb.<\/li><\/ul>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/jigarshah8055\/0fc00d29ee7d5f311d40bf40d9e737d5.js\"><\/script><\/p>\n\n\n\n<p><strong>Bingooo!!! That&#8217;s it..!!!<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Start your <a href=\"https:\/\/www.botreetechnologies.com\/ruby-on-rails-development\" target=\"_blank\" rel=\"noopener noreferrer\">rails server<\/a> and check it on the localhost.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><em>You can find complete codebase <a href=\"https:\/\/github.com\/jigarshah8055\/zipper\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/em><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Read Also :  <a href=\"https:\/\/www.botreetechnologies.com\/blog\/file-upload-with-box-using-ruby-on-rails\/\" target=\"_blank\" rel=\"noreferrer noopener\">File Upload with Box Using Ruby on Rails<\/a><\/p><p><\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.botreetechnologies.com\/contact\">Consulting is free<\/a> &#8211; let us help you grow!<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>This blog will guide you on how to create a&#8230;<\/p>\n","protected":false},"author":57,"featured_media":13306,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,10],"tags":[],"class_list":["post-9099","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Password Protected Zip Using Ruby on Rails - BoTree Technologies<\/title>\n<meta name=\"description\" content=\"Do you want to create a password-protected zip file using Ruby on Rails? Look at the steps outlined in this article and started zipping your files in Ruby from today.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Password Protected Zip Using Ruby on Rails - BoTree Technologies\" \/>\n<meta property=\"og:description\" content=\"Do you want to create a password-protected zip file using Ruby on Rails? Look at the steps outlined in this article and started zipping your files in Ruby from today.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-11T08:25:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-15T12:08:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jigar Shah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jigar Shah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\"},\"author\":{\"name\":\"Jigar Shah\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/7a96efcfb8c988a3ea96457104f3891a\"},\"headline\":\"Generating Password Protected Zip files using Ruby on Rails\",\"datePublished\":\"2020-03-11T08:25:48+00:00\",\"dateModified\":\"2021-09-15T12:08:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\"},\"wordCount\":262,\"commentCount\":16,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg\",\"articleSection\":[\"Ruby on Rails\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\",\"name\":\"Password Protected Zip Using Ruby on Rails - BoTree Technologies\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg\",\"datePublished\":\"2020-03-11T08:25:48+00:00\",\"dateModified\":\"2021-09-15T12:08:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/7a96efcfb8c988a3ea96457104f3891a\"},\"description\":\"Do you want to create a password-protected zip file using Ruby on Rails? Look at the steps outlined in this article and started zipping your files in Ruby from today.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg\",\"width\":1920,\"height\":1280,\"caption\":\"Generating Password Protected Zip Using Ruby on Rails\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Generating Password Protected Zip files using Ruby on Rails\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/7a96efcfb8c988a3ea96457104f3891a\",\"name\":\"Jigar Shah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/jigar-shah-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/jigar-shah-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/jigar-shah-150x150.png\",\"caption\":\"Jigar Shah\"},\"description\":\"I am a Ruby on Rails Developer. I like to to investigate requirements, design, execute, analyse, test, and upgrade the software\/applications. Outside of the tech world, I\u2019m a Photography fan. I\u2019m a nature, music and movie lover and do some of my best work while listening to my favourite albums.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Password Protected Zip Using Ruby on Rails - BoTree Technologies","description":"Do you want to create a password-protected zip file using Ruby on Rails? Look at the steps outlined in this article and started zipping your files in Ruby from today.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/","og_locale":"en_US","og_type":"article","og_title":"Password Protected Zip Using Ruby on Rails - BoTree Technologies","og_description":"Do you want to create a password-protected zip file using Ruby on Rails? Look at the steps outlined in this article and started zipping your files in Ruby from today.","og_url":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2020-03-11T08:25:48+00:00","article_modified_time":"2021-09-15T12:08:59+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg","type":"image\/jpeg"}],"author":"Jigar Shah","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Jigar Shah","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/"},"author":{"name":"Jigar Shah","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/7a96efcfb8c988a3ea96457104f3891a"},"headline":"Generating Password Protected Zip files using Ruby on Rails","datePublished":"2020-03-11T08:25:48+00:00","dateModified":"2021-09-15T12:08:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/"},"wordCount":262,"commentCount":16,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg","articleSection":["Ruby on Rails","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/","url":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/","name":"Password Protected Zip Using Ruby on Rails - BoTree Technologies","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg","datePublished":"2020-03-11T08:25:48+00:00","dateModified":"2021-09-15T12:08:59+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/7a96efcfb8c988a3ea96457104f3891a"},"description":"Do you want to create a password-protected zip file using Ruby on Rails? Look at the steps outlined in this article and started zipping your files in Ruby from today.","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/03\/rubyzip.jpg","width":1920,"height":1280,"caption":"Generating Password Protected Zip Using Ruby on Rails"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/password-protected-zip-using-ruby-on-rails\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Generating Password Protected Zip files using Ruby on Rails"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/7a96efcfb8c988a3ea96457104f3891a","name":"Jigar Shah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/jigar-shah-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/jigar-shah-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/jigar-shah-150x150.png","caption":"Jigar Shah"},"description":"I am a Ruby on Rails Developer. I like to to investigate requirements, design, execute, analyse, test, and upgrade the software\/applications. Outside of the tech world, I\u2019m a Photography fan. I\u2019m a nature, music and movie lover and do some of my best work while listening to my favourite albums."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/9099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=9099"}],"version-history":[{"count":2,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/9099\/revisions"}],"predecessor-version":[{"id":16332,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/9099\/revisions\/16332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/13306"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=9099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=9099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=9099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}