Rails Coding Standards

IN ESSENCE: ALL CODE SHOULD BE READABLE!

# DO NOT OPTIMISE for performance – OPTIMISE FOR CLARITY OF CODE

# STYLE: use 2 spaces for indent (not tabs)

# STYLE: Line up hash arrows for readability

# STYLE: put spaces around => hash arrows

# STYLE: put spaces after ‘,’ in method params – but none between method names and ‘(‘

# VIEWS: use HAML for views

# VIEWS: break up the structure with white space to help readability – VERTICALLY TOO!

# VIEWS STYLE: Rely on structure of page, without having to insert messages or new components…

# LOGIC: Rails Models should be as heavy as in logic and controllers should be lightweight as much as .

* Example: Effect to visually highlight then drop out an existing element rather than flash a message

* Example: Highlight newly added row rather than a message about it

# AVOID logic in views – they should be simple

# Views indentation should be well formatted.
not like this

<% for joke in @jokes %>
<div class="joke">
<p>
<%= h(truncate(joke.joketext, 20)) %>
<%= link_to 'Read this joke', {:action => 'show_joke', :id => joke} %>
</p>
<p class="author>
by <%= h(joke.author.full_name) %></p>
</div>
<% end %>

* put html generating logic into helpers

* instead of inline ruby logic, add to models (filtering, checking)

# NEVER use ActiveRecord models in migrations unless you re-define them within the migration

* …otherwise the migration fails when you later remove/rename the AR class

* BETTER SOLUTION: use bootstrapping until deployed!!!

# AJAX only for sub-components of an object, and avoid over-use


CONTROLLER CODING STANDARDS

1. Before filter should be added at the top of controller.

2. Before filter implementation should be immediate after filter declaration

3. Standard rails actions

4. Own custom actions

5. Inter-related actions should be clubbed together.

6. please, try to use of protected, private methods and they should be declared at the bottom of page in order.

7. Controller Actions should be like –
use 2 spaces for indent (not tabs)

def self.published_jokes
find(:all, :conditions => "published = 1")
end

MODEL CODING STANDARDS


#======= HEADER SECTION=========


# SCHEMA INFORMATION WILL BE HERE
# REQUIRE FILES WILL GO HERE

class Model < ActiveRecord::Base

#======== TOP ===================

# LIBRARY OR INCLUDE METHODS
# MODEL RELATIONSHIPS
# VIRTUAL ATTRIBUTES
# ACTIVE RECORD VALIDATIONS

#======== MIDDLE ===============
# CUSTOM VALIDATIONS
# PUBLIC METHODS

#======== BASE ==================
# PROTECTED METHODS
# PRIVATE METHODS

end

Cheers !!!
Sandip

High Performance Rails Hosting

There are lot of rails hosting, like wired tree,…,
i am still in search of cost effective and high performance hosting.

recently i came across with joyent rails hosting, please let me know your opinions..

Scale on Demand

Your rails infrastructure can be dynamically expanded or reduced within minutes.

Support Billions of Hits

The largest ruby on rails application running on Joyent does over 1 Billion page views a month. Joyent’s hardware load balancers make this kind of scale possible.
Ruby 1.8.6, Rails 2.1, Mongrel, Nginx

Everything you need to get rolling is pre-installed, including Ruby 1.8.6 and Rails 2.1, Apache, lighttpd, nginx and Mongrel.

Extremely Cost Effective

Static IPs, real storage, 10TB data transfer / bandwidth, and fantastic support all included.
Lightning Fast Speed

We provide direct connections to tier 1 internet back-bones, Force10 switches and f5 BigIP load-balancers.

Trusted by Companies like LinkedIn

Check out their post
Official Ruby on Rails Host

We’re the Official Ruby on Rails host. Go check it out at rubyonrails.org. “If you need hosting, Joyent is the official Ruby on Rails host, offering fantastic plans with a knowledgeable staff. Whether you need shared or dedicated hosting, these guys are experts in Ruby on Rails. “
Leverage a Large Community

Over 2,400 companies run Rails applications on Joyent. You gain from our experience hosting them and you can connect directly with them through the Joyent Forums and the Joyent Wiki

Entirely Open Loving Cloud

Joyent offers open protocols, open source solutions. Use any Language, any DB. You can move your application. No vendor lock-in.

please, help me……:(

Awesome: Working with the Rails console and all the tricks

Testing your active record methods using script/console

If you are using windows, you start the console by using this command:

ruby script\console
Linux:

./script/console

Just use the following command whenever you make changes to your model objects:

reload!

Instead of accessing your MySQL database with

mysql -u -p

You can instead do

script/dbconsole

and if you database has a password, just do

script/dbconsole -p


% script/dbconsole # connect to development database (or $RAILS_ENV)
% script/dbconsole production # connect to production database

Cheers !

$@ndip

%d bloggers like this: