Tuesday, July 27, 2010

Runner Delayed_job plugin with Daemon

Wokkers can be running in the background with daemon, following:


 > sudo gem install daemons


Create new file and paste these codes at the below

 /rails_app$ nano script/job_runner



#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'

dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))

daemon_options = {
  :multiple   => true,
  :dir_mode   => :normal,
  :dir        => File.join(dir, 'tmp', 'pids'),
  :backtrace  => true
}

Daemons.run_proc('job_runner', daemon_options) do
  if ARGV.include?('--')
    ARGV.slice! 0..ARGV.index('--')
  else
    ARGV.clear
  end

  Dir.chdir dir
  RAILS_ENV = ARGV[1] || ENV['RAILS_ENV'] || 'development'
  require File.join('config', 'environment')

  Delayed::Worker.new.start
end


To start daemon, running this code > ruby script/job_runner start ENV_NAME

 > ruby script/job_runner start development


Stop daemon, running this code > ruby script/job_runner stop ENV_NAME

 > ruby script/job_runner stop development

Monday, July 26, 2010

resolve "ActionController::RoutingError (No route matches "/favicon.ico" with {:method=>:get}):" log message

How to resolve this case.. i think when access the site, browser should be found the favicon.ico in public/ directroy. ok you just place the "favicon.ico" in the public/ directory
hope helpful :)

Tuesday, July 20, 2010

Ruby Toolbox

Hi All, here's the best reference tools how to working perfectly with Rails.. check it out http://ruby-toolbox.com

Thursday, July 15, 2010

!important

To avoid conflict between same reference the style code, author can add a bit more power by utilizing the !important operator, if use this operator the style will prior this reference style first. Here's the sample.


p{
 font-size:40pt !important;
}

Floating flash message

How to do floating flash message box on page site?

jQuery notice plugin can handle it, you can make your own the style, position, background-color etc.. i won’t talk much here. :) see the demo http://www.sandbox.timbenniks.com/projects/jquery-notice/ and follow the how the installation http://code.google.com/p/jquery-notice/wiki/Implementation

Tuesday, July 13, 2010

Using Capistrano to deploy Rails App with multiple environments

Firstly, you must install capistrano gem if you haven't


> sudo gem install capistrano


next, run this code " capify . " on your root Rails App to generate deploy.rb file, don't forget follow dot (.) at end of script


/app_root$ capify .


after execute that code, deploy.rb file has locate at root_app/config/deploy.rb
in this case i'll set deploy to multiple environments (production, development and staging)

open up the deploy.rb file and writes follow codes, in this case i used git repository (you can setup that with other repository like svn etc...)


abort "needs capistrano 2" unless respond_to?(:namespace)

set :stages, %w(development staging production)
set :default_stage, "production"
require File.expand_path("#{File.dirname(__FILE__)}/../vendor/gems/capistrano-ext-1.2.1/lib/capistrano/ext/multistage")

# =============================================================================
# REQUIRED VARIABLES
# =============================================================================
set :application, "my_app"  # CHANGE THIS LINE TO USE YOUR WEBSITE'S NAME
set :repository,  "git@you_app_pat.git"  # CHANGE THIS LINE TO USE YOUR SCM REPO
set :directory_path, "/opt/rails_apps/my_app"

# =============================================================================
# ROLES
# =============================================================================
role :web, "sample.com"  # CHANGE THESE LINES TO USE YOUR OCS SERVER NAME
role :app, "sample.com"
role :db,  "sample.com", :primary => true

# =============================================================================
# OPTIONAL VARIABLES
# =============================================================================
set :user, "root"
set :scm, :git
set :scm_username, "arul"
set :scm_passphrase,  Proc.new { Capistrano::CLI.password_prompt('Git Password: ') }

set :runner, "www-data"
set :use_sudo, false
set :branch, "master"
set :deploy_via, :checkout
set :git_shallow_clone, 1
set :scm_verbose, true

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

# =============================================================================
# TASKS
# =============================================================================
namespace :deploy do
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "rm -rf #{current_path}/config/database.yml"
    run "rm -rf #{current_path}/config/app_config.yml"
    run "rm -rf #{current_path}/public/system"
    run "rm -rf #{current_path}/public/images/photos"

    run "ln -s #{directory_path}/shared/config/database.yml #{current_path}/config/database.yml"
    run "ln -s #{directory_path}/shared/config/app_config.yml #{current_path}/config/app_config.yml"
    run "ln -s #{directory_path}/#{stage}/shared/system #{current_path}/public/system"
    run "ln -s #{directory_path}/#{stage}/shared/images/photos #{current_path}/public/images/photos"
    run "touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end


let's make "deploy" directory to root_app/config/ and create new files there (production.rb, development.rb and staging.rb)

/app_root$ mkdir config/deploy
/app_root$ touch config/deploy/production.rb config/deploy/development.rb config/deploy/staging.rb


now, let's begin to coding hee..hee :)
write this codes for every files:
"production.rb" file

set :deploy_to, "/opt/rails_apps/#{application}/production"
set :rails_env, 'production'


"development.rb" file

set :deploy_to, "/opt/rails_apps/#{application}/development"
set :rails_env, 'development'


"staging.rb" file

set :deploy_to, "/opt/rails_apps/#{application}/staging"
set :rails_env, 'staging'


So, that's all
now you can deploy in every environmets, just run these codes:

=> production env

> cap production deploy


=> development env

> cap development deploy


=> staging env

> cap staging deploy


Hope Helpul :)

Plurarize word in I18n structure yml file

Here's the rules of pluralization texts, for example:

In English language

en:
   blog:
     view:
       one: "1 View"
       other: "{{count}} Views"


In Indonesia language

id:
   blog:
     view:
       one: "1 Terlihat"
       other: "{{count}} Kali terlihat"


well, you can call this code in View :


<%= t('blog.view', :count => number) %>

Problem installing add ons on FF (Ubuntu Linux)

Hi, if you have same problem with this.. here's the best way : http://ubuntuforums.org/showthread.php?t=1311774

Thursday, July 8, 2010

Generating SSH keys on Linux

The SSH keys was saved on .ssh directory.
Firsly, make sure you have backup the old ssh keys if you want to backup your ssh keys follow these steps:

> cd ~/.ssh
> ls -al


if the ssh keys already exist, backup your ssh keys

> mkdir key_backup
> cp -rf id_rsa* key_backup
> rm -rf id_rsa*


Now, let's us make a new ssh key and the intruction. See Working with SSH key passphrases

> ssh-keygen -t rsa -C "arul@local.com"


Print out your ssh key

> cat ~/.ssh/id_rsa.pub

Wednesday, July 7, 2010

deploy with Capistrano raise "Symbolic link not allowed or link target not accessible:" when access on site using SUSE 11.1 Linux

When i'm deploying my project to server, i can't access the site (Forbidden Access) then i check the log file at > tail -f /var/log/apache2/error_log
there are raise something like this "Symbolic link not allowed or link target not accessible:". I had tried everything, change owner, change permissions, set "Options FollowSymlinks" in my Vhost conf.. etc, but it didn't work.

Next, i'm checking conf at httpd.conf.. wahh there are got thing wrong script, like the following.

> vi /etc/apache2/httpd.conf



# forbid access to the entire filesystem by default
<directory>
    Options None 
    AllowOverride None
    Order deny,allow
    Deny from all
</directory>

"Options None", it's should be "FollowSymlinks".
Well, the solution i must change a line script below:

# forbid access to the entire filesystem by default
<directory>
    Options FollowSymlinks
    AllowOverride None
    Order deny,allow
    Deny from all
</directory>

Final, next i just to restart my server

> /etc/init.d/apache2 restart

It's All.. hope helpful.

Tuesday, July 6, 2010

Install Subversion with web access on Ubuntu Linux

Subversion control is an open source version control system. Using Subversion you can record your projects history, here you can manage your project and save change with a version number.

Installation.
To access the subversion repository from HTTP protocol, you must install and configure webserver. in this section we are using Apache2 as Server.

To install subversion run these code:

> sudo apt-get install subversion libapache2-svn



We are going to create svn repository on /home/svn

> mkdir /home/svn
> cd /home/svn
> mkdir repo


Well, let's begin to create repository here:

> svnadmin create /home/svn/repo



Will create a group name is "subversion" and replace USERNAME with actually username

> sudo addgroup subversion
> sudo usermod -a -G subversion USERNAME
> sudo usermod -a -G subversion www-data
  


Set file permissions:

> sudo chown -R www-data:subversion /home/svn/repo
> sudo chmod -R g+rws /home/svn/repo


Now, we are going to configure Vhost with svn access.. if you want to see Example subversion configuration apache2. run these code:

> sudo gedit /etc/apache2/mods-enabled/dav_svn.conf


That's an example file configuration to svn access on HTTP protocol.
in this case i want to show you how the svn repository can access per website url, you must configure it at /etc/apache2/sites-available/your_site.conf and paste code below:


  <location svn="">
     DAV svn
     SVNPath /home/svn/repos
     AuthType Basic
     AuthName "Subversion Repository"
     AuthUserFile /etc/subversion/passwd
     Require valid-user
  </location> 



Ok, a little remaining setup now!
you must create /etc/subversion/passwd file. This file contains user authentication access.
-c using for replacing existing user

> sudo htpasswd -c /etc/subversion/passwd USERNAME
> New password: 
> Re-type new password: 



Restart your server:

> sudo /etc/init.d/apache2 restart


If you are uncertain whether the passwd file exists, you can check this with run this command:

> cat /etc/subversion/passwd



Now, to access the repository you can run the following command:

> svn co http://hostname/svn/repo myproject --username user_name

Configure passenger on SUSE 11.1 Linux

Intall require package, following:

> yast2 -i gcc gcc-c++ make automake git ruby ruby-devel rubygems mysql mysql-client libmysqlclient15 libmysqlclient-devel ruby-mysql zlib gzip unzip memcached ImageMagick ImageMagick-devel ruby-RMagick ruby-RMagick-doc libxml2 libxml2-devel libxslt libxslt-devel yaz libyaz-devel idzebra idzebra-devel curl libcurl-devel libreadline5 readline-devel apache2 apache2-devel 

> yast2 -i wv wv-devel poppler-tools libpoppler4 poppler-data lynx


> yast2 -i libexif exiftool


Install passenger (follow the wizard intructions).

> passenger-install-apache2-module


Put these lines to end of file in httpd.conf, edit the file at /etc/apache2/httpd.conf

LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/local/bin/ruby


Add a Vhost and locate them to your doc apps

> vi /etc/apache/vhosts.d/filename.conf (will create new file, if not exist)

add these line

<VirtualHost *:80> 
  ServerName www.yourdomain.com
  ServerAlias your_alias_name.com
  DocumentRoot /app_path/public
  RailsEnv production
  <Directory /app_path/public>
    Options Indexes FollowSymLinks
    Options -MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>


well, now we just to restart the apache server.

> /etc/init.d/apache2 restart

Monday, July 5, 2010

irb with hirb


+----+---------------+-------------+-------------------------+-------------------------+
| id | name          | description | created_at              | updated_at              |
+----+---------------+-------------+-------------------------+-------------------------+
| 1  | Sports        | lorem ipsum | 2010-07-01 09:05:26 UTC | 2010-07-01 09:05:26 UTC |
| 2  | Fun           | lorem ipsum | 2010-07-01 09:05:26 UTC | 2010-07-01 09:05:26 UTC |
| 3  | Politics      | lorem ipsum | 2010-07-01 09:05:26 UTC | 2010-07-01 09:05:26 UTC |
| 4  | Lifestyle     | lorem ipsum | 2010-07-01 09:05:26 UTC | 2010-07-01 09:05:26 UTC |
| 5  | Entertainment | lorem ipsum | 2010-07-01 09:05:26 UTC | 2010-07-01 09:05:26 UTC |
+----+---------------+-------------+-------------------------+-------------------------+


How to print structure table to screen of terminal, it's possible with hirb gem
sample intruction here:

> sudo gem install hirb

require your own the hirb gem.


> nano ~/.irbrc


include this script.

require 'rubygems'
require 'hirb'
Hirb.enable

Now, you can enjoy to test

> script/console
> Model.all

hope helpful