loading...

Friday, December 24, 2010

Basic principles of Ruby on Rails (RoR 3)

The basic principles of the emerging framework  Ruby on Rails (RoR) are
  • Conventions over Configuration
  • DRY: Don’t Repeat Yourself
  • REST interface
Lets see the above mentioned principles in detail

Conventions over Configuration(CoC)
The concept conventions over configurations comes from the fact that Rails assumes a number of defaults.The naming conventions of rails application will be related to the database tables and generated models.

Examples makes you a clear view of CoC
Suppose you have a model  named order then the rails will look for the database named orders.

in the above example the model name order is in singular and the database name orders is in plural.this means that rails is very much aware of plurals too.

Similarly, if we have a controller named Archive, then Rails assumes:
  • The class is called ArchiveController, saved in the file archive_controller.rb within the app/controllers/ directory.
  • That there  exists a helper module called ArchiveHelper in the file archive_helper.rb within theapp/helpers/ directory.
  • The templates for the views of this controller reside in the app/views/archive/ directory.
Advantages of CoC principle 
  • easier for other programmers to understand your code
  • possible to override the conventions.
DRY: Don’t Repeat Yourself
DRY (Don’t Repeat Yourself) sounds quite self-explanatory, developers are not encouraged  to express a piece of information/knowledge/code repeatedly in more than one place.

Advantages of DRY
  • maintains clean code
  • reduces errors
  • reduces time
link :REST interface

for more details view of rails 3 principles look for following links
http://wiki.rubyonrails.org/getting-started/overview/tenets

No comments:

Post a Comment

fuzionpro Headline

fuzionpro