How to install Passenger on Ubuntu

How to Install Passenger on Ubuntu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# As a root
$ gem install passsenger
$ passenger-install-apache2-module

# Modify /etc/apache2.conf
Add LoadModule, PassengerRoot

# Restart Apache
sudo /etc/init.d/apache2 restart

# Add config/setup_load_paths.rb
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
  begin
    gems_path = ENV['MY_RUBY_HOME'].split(/@/)[0].sub(/rubies/,'gems')
    ENV['GEM_PATH'] = "#{gems_path}:#{gems_path}@global"
    require 'rvm'
    RVM.use_from_path! File.dirname(File.dirname(__FILE__))
  rescue LoadError
    raise "RVM gem is currently unavailable."
  end
end

# If you're not using Bundler at all, remove lines bellow
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'
Facebook Twitter

Rails – Display Custom Error Pages

How to display custom error pages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#application.rb
config.exceptions_app = self.routes

#routes.rb
match '/404' => 'errors#page_not_found'
match '/500' => 'errors#server_error'

#errors_controller.rb
class ErrorsController < ApplicationController
  def page_not_found
    render :status => 404
  end

  def server_error
    render :status => 500
  end
end

Test it!

Important!

Change the following configuration is test.rb
Rails.application.config.consider_all_requests_local = false
Rails.application.config.action_dispatch.show_exceptions = true

1
2
3
4
5
6
7
8
require 'spec_helper'

feature 'Error Pages' do
  scenario 'user visits page page not found' do
    visit '/xxxx'
    expect(page).to have_content("The page you are looking for doesn't exist.")
  end
end
Facebook Twitter

Sublime

Customizing sublime.

Add sublime to the command line

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

Detect Syntax

git clone git://github.com/phillipkoebbe/DetectSyntax.git

SCSS

git clone -b SublimeText2 git://github.com/kuroir/SCSS.tmbundle.git SCSS

 

Facebook Twitter

Eloquent Ruby

Eloquent Ruby by Russ Olsen

The ruby community is full of un-written rules, conventions that people have agreed upon over time which can be a little confusing for somebody who is trying to learn Ruby for the first time.

Eloquent Ruby provides a good overview of the Ruby language explaining some of the conventions the community has adopted. A good read for beginners and even advanced developers.

 

 

Facebook Twitter

Open Sinatra console

Open Sinatra Console like this:

$ irb -r ./sinatra_app.rb

OR

$ pry -r ./sinatra_app.rb (if you prefer pry)

 

Facebook Twitter

Making generators in Rails 3

How to make a generator for your gems?

Check it out in github

The structure:

 

The Code:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# install_generator.rb
require 'rails/generators/migration'
require 'rails/generators/active_record'
module LoggableEvent
  module Generators
    class InstallGenerator < Rails::Generators::Base
      include Rails::Generators::Migration
      source_root File.expand_path('../templates', __FILE__)
 
      def generate_model
        copy_file 'log.rb', 'app/models/log.rb'
        migration_template 'create_logs.rb', 'db/migrate/create_logs.rb'
        say "Start logging!"
      end
     
      def self.next_migration_number(path)
        ActiveRecord::Generators::Base.next_migration_number(path)
      end
     
    end
  end
end

 

 

 

The results?
rails generate loggable_event:install

Facebook Twitter

Merging a Pull Request

Merging a pull request

 

git checkout -b test_branch  //Create a new brach to test

git remote add remote_name git://github.com/remote/remote.git  //Add remote

git fetch remote_name //Fetch remote branch

git merge remote_name/branch_name //Merge remote branch use git merge remote_name/master if you are merging master

**** Test pull request, make changes, test again and commit.. ***

git checkout master //Go back to your master

git merge test_branch //Merge the test_branch

git push origin master //Push master


**** Github will automatically close the pull request for you ***

 

Facebook Twitter

Run tests with Rspec and Rake

require ‘rspec/core/rake_task’

RSpec::Core::RakeTask.new(‘spec’)

task :detault => :spec

Facebook Twitter

brew update not working

brew update not working?

 

$ cd /usr/local

$ git fetch origin

#if origin doesn’t exist

$ git remote add origin git://github.com/mxcl/homebrew.git

$ git reset –hard origin/master

Facebook Twitter

Arrays

 

Facebook Twitter