DEV Community

jigarshah8055
jigarshah8055

Posted on

Password Protected Zip Using Ruby on Rails

This blog will guide you on how to create a Ruby on Rails application and add rubyzip which used to make zip files with Password Protection.

Let’s have a brief introduction about Password Protection using rubyzip. If you are familiar with rubyzip and Password Protection then directly go to Implementation section.

What is rubyzip ?

  • It’s a ruby gem (library) which is used to read and write zip files.
  • rubyzip provide you the power of reading and writing zip files and also make password protected zip files.

Why rubyzip?

  • rubyzip provides traditional password protection.

Requirements

  • Ruby 1.9.2 or greater

Technology Stack

get started

Implementation

  • Create a new rails app

    rails new zipper --database=postgresql

  • Now put gem in the gemfile as

    gem 'rubyzip', '>= 1.0.0'

    Don’t forget to bundle ;)

  • Generate a controller with the create and new method

    rails g controller zipping_folders new

  • Simply set the root path to zipping_folders new method and make resource path for only create method in routes.rb

    resources :zipping_folders, only: [:create]
    root ‘zipping_folders#new’

  • Now make a form in new.html.erb with one file tag to choose files and two input fields which define zip file name and password respectively.

  • You have to write below code in zipping_folders_controller.rb.

Bingooo!!! That's it..!!!

  • Start your rails server and check it on localhost.

You can find complete code on

https://github.com/jigarshah8055/zipper

Top comments (0)