How to set up ( Fedora php ruby on rails )

Thursday, December 30, 2010

CodeRay with Ruby On Rails 3

Code highlight in Ruby On Rails 3 Using CodeRay

First open your Gemfile and add

gem 'coderay'

and run bundle install

bundle install

Next you need to add a method any where you want best place would be ApplicationController

def coderay(text)
text.gsub(/<code( lang="(.+?)")?>(.+?)<\/code>/m) do
CodeRay.scan($3, $2).div(:css => :class)

Suppose you have controller Post and it's action show

def show
@post = Post.find(params[:id])
@post.body = coderay(@post.body)

now in view file change following

<%= @post.body %>


<%= sanitize @post.body %>

Now you need a stylesheet that define color scheme for your code{/* attribute name fat */}{/* attribute name */}
span.av{/* attribute value */}{/* attribute value fat */}{/* bin */}
span.c{/* comment */}{/* char */}{/* class*/}{/* colour */}{/* constant */}{/* class variable */}
span.df{/* definition */}
span.di{/* directive */}
span.dl{/* delimeter */}{/* doc */}
span.ds{/* doc string */}
span.e{/* escape */}{/* error */}
span.ex{/* exception */}
span.fl{/* float */}
span.fu{/* function */}
span.gv{/* global variable */}
span.hx{/* hex */}
span.i{/* integer */}
span.ic{/* include */}{/* ident */}{/* inline */}{/* interpreted */}
span.iv{/* instance variable */}
span.k{/* content */}{/* css attribute */}{/* css selector */}{/* label */}{/* local variable */}
span.mod{/* modifier */}
span.oc{/* oct */}
span.on{/* operator name */}
span.op{/* operator */}
span.pc{/* pre constant */}{/* pre type */}
span.pd{/* predefined */}
span.pp{/* preprocessor */}
span.rx{/* reg exp */}
span.r{/* reserved */}
span.s{/* string */}{/* shell */}
span.sp{/* space */}{/* symbol */}
span.ta{/* tag */}{/* tag fat */}
span.ts{/* tag special */}
span.ty{/* type */}
span.v{/* variable */}
span.vl{/* css value */}
span.xt{/* xml text */}

Wednesday, December 29, 2010

How to update rails site hosted on Heroku

So how to update changes made locally to remote server

Very simple to do that, make amendments in your project and than follow these steps

Note: Be sure you are in root of application directory

[rubyonrails@localhost rails_sandbox]$ git add .

[rubyonrails@localhost rails_sandbox]$ git commit -m "some message here"

[rubyonrails@localhost rails_sandbox]$ git push heroku master

Ruby on Rails Free Hosting

Hosting Ruby On Rails Free

Host rails 2 or rails 3 apps for free and easily

Once you set up a site, you can set up as many sites as you want

If you are a Rails developer and want to host for free for testing purpose check-out

For this you need to sign-up for two sites first is Heroku and other is github..
After sign-up go to quick start page of and follow instructions and in the end you would have a hosted rails application

Need Help:

Do comment