September 24, 2008

Coding Guideliness in Rails

Rails an active framework in today’s web2.0 world, so to stay updated and make coding easy just with very little tricks and tips while you code.
The best part of rails is its truly flexible in terms of various programming paradigms. So for better coding standards we can use the below given styles and make our life easy, the best part is rails make code in human readable form.

Use the below given guidelines:-
Use Active record finders.http://weblog.jamisbuck.org/2006/10/7/helping-activerecord-finders-help-you
Use named_scope for finding nested models.http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-finder-functionality
Pass params as params not @params.
@params is deprecated, in rails 2.x versions.
Only have instance variables which are needed in views.
Create local variables which are needed within methods.
Keep all initializers in config/initializers file.
Keep simple routes by using namespaces & resources.
Use proper rdoc commenting for documentation purposes.
Use understandable naming convention for methods, variables & other definitions.
Generalize structure before you start, like have certain flow diagrams which will help in better coding.

No comments: