Skip to main content

Posts

Showing posts from January, 2019

Ruby dotenv gem

Dotenv ruby gem loads environment variables from .env file. Install gem gem 'dotenv-rails', groups: [:development, :test] Reference: Dot env gem run bundle install. Create .env file at root directory. Add secret keys to env as variables. Whenever application loads these variables can access with the ENV. Add variables to .env file. APP_ID=1edf344g STRIPE_SECRET_KEY=dfjdhjdf787dfjnnsasdb222bhd Access env varibles like ENV["APP_ID"] and ENV["STRIPE_SECRET_KEY"]

Upload ZIP files with paperclip gem

Paperclip is a ruby library to attach files for active record.   gem 'paperclip' run bundle install. Generate a column to the table with paperclip rails migration generator. rails g paperclip project download_file. run rake db:migrate has_attached_file :download_file validates_attachment_content_type :download_file, :content_type => ["application/zip", "application/x-zip"] download file is field in database table.  validates attachment content type is zip (We uploading zip files). Add download_file to strong params. params.require(:projects).permit(:download_file, .......)  Add download_file field to form. <div class="form-group">     <label>ZIP Final</label>     <%= form.file_field :download_file, class: "form-control", placeholder:           "Upload zip file" %> </div>

How to disable rdoc and ri when install gems.

Ri and rdoc will install automatically when your install the gems. Install single gem without ri and rdoc. gem install rails --no-ri --no-rdoc In server you do not need to wait around for rdoc and ri install for each gem in gemfile. You can disable for gem installs and updates. create file ~/.gemrc or /etc/gemrc Add a line to gemrc gem: --no-rdoc --no-ri Resources RVM Documentation