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.