Setup Existing Project

  • Install rbenv if not installed.
  • create two hidden files .ruby-version and .rbenv-gemsets in main/root folder of project.
    • add ruby version in .ruby-version file. e.g: 2.2.1
    • give a name to gemset where all the gems will be install for this project in .rbenv-gemsets. e.g: abc
  • Open terminal and go to project directory using ‘cd’ command.
    • run command: ‘rbenv gemset active’
    • it will display the gemset name which you just mentioned in .rbenv-gemset file.
    • install bundler using “gem install bundler” if not installed
    • run command: ‘bundle install’
    • install missing libs if bundle install does not get succeeded.
  • Open database.yml and edit it according to your local setup.
  • Again switch back to terminal:
    • create database using: ‘rake db:create’
    • run migration: ‘rake db:migrate’
    • run seed: ‘rake db:seed’

Create and integrate SSL certificate in Rails app Using [ Godaddy + Nginx(1.8) + Puma + Ubuntu Server(14.04 LTS) ]

Learning with Earning

Login to your server by ssh and then:

  1. Create file YOUR_RAILS_APP_DIRECTORY/config/puma.rb
    Below is puma.rb file content:
    #!/usr/bin/env puma
    directory '/home/ubuntu/YOUR_RAILS_APP_DIRECTORY/public/'
    rackup '/home/ubuntu/YOUR_RAILS_APP_DIRECTORY/'
    environment 'production'
    daemonize true
    pidfile '/home/ubuntu/YOUR_RAILS_APP_DIRECTORY/tmp/pids/'
    state_path '/home/ubuntu/YOUR_RAILS_APP_DIRECTORY/tmp/pids/puma.state'
    stdout_redirect '/home/ubuntu/YOUR_RAILS_APP_DIRECTORY/log/puma.log'
    threads 2, 5
    bind 'unix:///home/ubuntu/YOUR_RAILS_APP_DIRECTORY/tmp/sockets/puma.sock'
    workers 2
  2. Generate CSR certificate
     openssl req -new -newkey rsa:2048 -nodes -keyout SITE_DOMAIN_NAME.key -out SITE_DOMAIN_NAME.csr

    Note: For instance site domain is then you will place only facebook.key and facebook.csr

  3. .key file will be used in nginx configurations.
    Copy .csr file’s content and then paste its content to godaddy CSR field.

    After generating ssl certificate using godaddy, download it. Then upload that downloaded zip to Ubuntu Server using scp command.

  4. Unzip the folder there will be two .crt files in it. Chain those files using this command.
    cat file_name.crt  file_containing_bundle_in_name.crt > some_name.chained.crt

    Note: Place them .chained.crt file in that order that file containing bundle in its name comes after like above…

View original post 224 more words

Basic Development Flow

1) Get up to date

git checkout master
git pull

2) Create new branch for feature

git checkout -b [ticket_no]/features/[feature_name]

3) Do a bunch of work

git add some files that have changed or added
git rm some files that have been removed

and then run test cases if you have.

4) Commit often

git commit -m "a comment about what you changed "

5) Keep up to date

git checkout master
git pull

6) Rebase master back into the feature branch

git rebase master [ticket_no]/features/[feature_name] 

This will put you back into your feature branch, you may need to resolve conflicts here.

7) Integrate your feature into master, Make sure your branch is up to date with master

git checkout master
git merge --no-ff [ticket_no]/features/[feature_name]
git push origin master

There should be no conflicts on master, they have been handled by keeping the feature branch up to date.
If the push to master fails, then someone beat you to it!
Simply go back and do the ‘Keep up to date’ step then try to integrate your feature into master again.

rebase master back into the feature branch

git rebase master [ticket_no]/features/[feature_name]

This will put you back into your feature branch
You may need to resolve conflicts here.

Heroku Commands

  1. check log:
    Heroku logs -t

    More over:

    heroku logs --source app -t --ps web -a [app_name]

    Filter used in above command are for:
    –source app => logs generated from within your application
    –ps web/worker => to fetch logs with a certain source(web/worker/router)

  2. enlist environment variables:
    heroku run console 
    config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]
  3. open terminal at heroku:
    heroku run bash

    And here you can do anything like local terminal. e.g: check database.yml

    cat database.yml
  4. List all the process:
    heroku ps -a myapp
  5. To kill any process:
    heroku ps:stop [process_name_along_dot_followed_by_number]
    heroku ps:stop run.5479

Install Ruby on Rails in Ubuntu 14.04 LTS


Here is step by step instruction on how to set up ruby on rails in ubuntu 14.04 LTS

Installing Ruby using RVM:

First you have  to install  some dependencies for Ruby.

Now install ruby with RVM using those commends:

Installing Rails:

Rails comes with so many dependencies like NodeJS

To install NodeJS, we’re going to add it using a PPA repository:

Now run for install rails:

Setting Up MySQL:

You can install MySQL server and client from the packages in the Ubuntu repository.

Setting Up PostgreSQL:

For PostgreSQL, you need to add a new repository to easily install a recent version of Postgres 9.3.

For postgres you need to set up a user.

Test your settings for new install:

All done. Now visit http://localhost:3000 to view your new application.

Enjoy. Happy Coding 🙂

View original post

Different ways of Iterating over an Array in Ruby (Just for me)

1) .each do |val| … end

2) .each_with_index do |val, index| … end

3) a) .map do … end  => returns new array

b) .map.with_index do |val, index| … end

4) .any? do |val| {condition} end   => returns true or false

5) .all? do |val| {condition} end   => returns true if all value satisfy the condition otherwise false

6) .select do |val| {condition} end   => returns an array of those values which satisfy condition.

7) .find do |val| {condition} end   => returns first value which passes condition.

8) .find_all do |val| {condition} end   => returns all those value which satisfy conditon. It’s equivalent to .select

9) .inject([initial_value_of_var1]) do |var1, var2 | … end => returns var1


Loops and Repetitions in Ruby

1) times:

[integer].times do |i| ... end


5.times do |i|
  puts "iteration: #{i}"

2) upto:

[start_val].upto [end_val] do |i| ... end


1.upto 5 do |i|
  puts "iteration: #{i}"

3) downto:
it’s inverse of upto.

[end_val].downto [start_val] do |i| ... end


5.downto 1 do |i|
  puts "iteration: #{i}"

4) step:

We can do both upto and downto with step loop. It’s very flexible.

a) [start_val].step [end_val] do |i| ... end
1.step 5 do |i|
  puts "Iteration: #{i}"

for stepping:

b) [start_val].step [end_val], [incremental_val] do |i| ... end
1.step 5, 2 do |i|
  puts "Iteration: #{i}"

like downto:

c) [end_val].step [start_val], -1 do |i| ... end
5.step 1, -1 do |i|
  puts "Iteration: #{i}"

5) while

while conditional [do]

i = 1
while i <= 5 do
  puts "Iteration: #{i}"
  i += 1


code while condition


end while conditional

i = 1
  puts "Iteration: #{i}"
  i +=1
end while i < 5

7) until
It’s similar to while but having reverse condition.

i = 1
until i > 5 do
  puts "Iteration: #{i}"
  i += 1

8) for

for [var_name] in [rang] do ... end
for i in (1..10) do
  puts "Iteration: #{i}"

9) each

[rang].each do |[var]| ... end
(1..10).each do |i|
  puts "Iteration: #{i}"