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’
Advertisements

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/config.ru'
    
    environment 'production'
    daemonize true
    
    pidfile '/home/ubuntu/YOUR_RAILS_APP_DIRECTORY/tmp/pids/puma.pid'
    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 facebook.com 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.

Install Ruby on Rails in Ubuntu 14.04 LTS

Salayhin

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

 

Marshaling Objects

Ruby can take an object and convert it into a stream of bytes that can be
stored outside the application. This process is called marshaling.
This saved object can later be read by another instance of the application (or by a totally
separate application), and a copy of the originally saved object can be
reconstituted.
Rails uses marshaling to store session data.