Skip to content

Instantly share code, notes, and snippets.

@danielres
Created November 7, 2010 22:30
Show Gist options
  • Save danielres/666936 to your computer and use it in GitHub Desktop.
Save danielres/666936 to your computer and use it in GitHub Desktop.
generate a functionnal rails application on alwaysdata
# General Apache options
AddHandler fcgid-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
# RewriteCond %{REQUEST_URI} ^/notrails.*
# RewriteRule .* - [L]
# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On
# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
# Alias /myrailsapp /path/to/myrailsapp/public
# RewriteBase /myrailsapp
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
# ErrorDocument 500 /500.html
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

Usage

Use command:

bash <( curl https://gist.github.com/raw/666936/rails_on_alwaysdata.sh ) MYAPP

Where MYAPP is the name of your rails application

Compatibility

Works like a charm with rails 2.3.8 on ruby 1.8.7

Installing gems

Procedure:

  1. Add this to ~/.bash_profile:

    export PATH="$HOME/bin:$HOME/.gem/bin:$PATH" export GEM_PATH="$HOME/.gem"

  2. Install gems in ~/.gem folder:

    cd ~ mkdir .gem cd .gem gem install compass --no-ri --no-rdoc -i .

  3. Add this line into config/environment.rb (on top), where USERNAME is your client user name:

    ENV['GEM_PATH'] += ':/home/USERNAME/.gem/'

Compass

Initializing Compass for a rails app

compass init rails PATH/TO/MYAPP --using blueprint/semantic

Yaml_db

Installing Yaml_db plugin to dump the db contents to a yaml file

ruby script/plugin install git://github.com/adamwiggins/yaml_db.git
#!/bin/bash
# restore rails permissions lost by git operations
# usage:
# bash <( curl https://gist.github.com/raw/666936/fix_perms.sh )
#
find public -type d -exec chmod 0755 {} \;
find public -type f -exec chmod 0644 {} \;
chmod 0755 public/dispatch.*
chmod -R 0755 script
#!/bin/bash
# USAGE:
# bash <( curl https://gist.github.com/raw/666936/rails_on_alwaysdata.sh ) MYAPP
# where "MYAPP" is the name of your rails application
rails $1 --with-dispatchers
cd $1
#wget http://dev.rubyonrails.org/export/9250/trunk/railties/configs/apache.conf
#mv apache.conf public/.htaccess
#sed -i 's/dispatch.cgi/dispatch.fcgi/g' public/.htaccess
#sed -i 's/AddHandler fastcgi-script .fcgi/AddHandler fcgid-script .fcgi/g' public/.htaccess
#sed -i 's/!\/usr\/languages\/ruby\/1.8.7\/bin\/ruby1.8/!\/usr\/bin\/ruby/g' public/dispatch.fcgi
wget https://gist.github.com/raw/666936/f14cd4c6da9164fb92351ec8f75fb178ea703a98/.htaccess
mv .htaccess public/
sed -i 's/!\/usr\/languages\/ruby\/1.8.7\/bin\/ruby1.8/!\/usr\/bin\/ruby/g' public/dispatch.fcgi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment