Showing posts with label Rails. Show all posts
Showing posts with label Rails. Show all posts

Wednesday, January 1, 2014

How to: Ruby on Rails + Ubuntu + Apache with Passenger

Now you can use gem to install Rails:

sudo gem install rails


Install Phusion Passenger (an Apache module that lets you run Rails apps easily):

sudo gem install passenger

sudo passenger-install-apache2-module


The passenger-install-apache2-module script will guide you through what you need to do to get Passenger working. It should tell you to copy these lines into your /etc/apache2/apache2.conf:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so

PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2

PassengerRuby /usr/bin/ruby1.8


Create a file in /etc/apache2/sites-available/ for your site (something like 'irorio.local.jp') and insert this:
<VirtualHost *:80>
        alias /iapps /home/taind/svn/branch/irorio/irorio-api/public
        ServerName irorio.local.jp
        DocumentRoot /home/taind/svn/branch/irorio/irorio
        DirectoryIndex index.php
        SetEnv APPLICATION_ENV development
        <Directory /home/taind/svn/branch/irorio/irori>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        <Location /iapps>
                PassengerBaseURI /iapps
                PassengerAppRoot /home/taind/svn/branch/irorio/irorio-api
        </Location>
        <Directory /home/taind/svn/branch/irorio/irorio-api/public>
                Options -MultiViews
                Allow from all
        </Directory>
        RailsEnv development
        #RailsBaseURI /iapps
</VirtualHost>

Thursday, September 26, 2013

Frequently used commands in Rails vs Slim

render :text => 'test'

# set layout
layout 'layout'

# print odd and even in table
tr class=cycle('list_line_odd', 'list_line_even')

# ruby inside javascript block [slim template]
javascript:
  var config = { 
    custom: "#{my_value ? 'truthy' : 'falsy'}",
    current_user: #{raw current_user.to_json}
  };

Friday, September 20, 2013

Ruby on Rails + Slim & Nginx + Unicorn

The first, you must install Ruby and Rails for your computer.
Deploy website on Nginx & Unicorn

Install Nginx
$ sudo apt-get install nginx
Setup virtual host for Nginx. Open file /etc/nginx/sites-available/your_domain.name and add below lines:
server {
        listen 80;
        server_name your_domain.name;
        root /document_root;
        index index.php;
        #access_log  /var/nginx/access.log
}


Install Unicorn
$ gem install unicorn
Setup Unicorn to process request for Ruby Application on Nginx. Continue add more below lines into setup files of nginx
upstream unicorn {
  server unix:/tmp/unicorn.hello.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  server_name hello.jp;
  root /home/taind/svn/demo/hello;

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}
Add a boot loader file file Unicorn in document_root/config/unicorn.rb
root = "/home/taind/svn/demo/hello"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"

listen "/tmp/unicorn.hello.sock"
worker_processes 2
timeout 30

# Force the bundler gemfile environment variable to
# reference the capistrano "current" symlink
before_exec do |_|
  ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile')
end

After finish all above steps, you just start Nginx and Unicorn
Start Nginx
$ service nginx start
Start Unicorn
unicorn_rails -c document_root/config/unicorn.rb -D


Setup Slim template
How to start?
Install Slim as a gem:
$ gem install slim

Include Slim in your Gemfile with gem 'slim' or require it with require 'slim'. That's it! Now, just use the .slim extension and you're good to go.