SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Saturday, October 10, 2009

Ruby on Rails - Short Summary

This article is for my own reference, my honourable thanks to the author Alanbradburne


Models: ActiveRecord


ActiveRecord is what is known as an Object/Relationship Mapping (ORM) library. An ORM library maps the data stored in a database to a class in your application. This allows you to access your data without having to worry about the SQL queries or even exactly how the data is accessed. The rows in each database table become instances of an object. Although this sounds complex, in practice, it makes working with a database incredibly simple and easy.
In a Rails application, all of the interaction with the database is performed through ActiveRecord, so learning how to get the most from it is important.



Views and Controllers: ActionPack


ActionPack is simply a collection of libraries and tools to help you build web applications.These provide the “view” and “controller” of the MVC stack.
The view part of ActionPack is used to create the web pages themselves. Since virtually all of the pages in our site will be dynamic (i.e., not static HTML files), ActionPack provides a lot of helper functions to allow us to insert the dynamic data into a page.
The controller part of ActionPack is the glue that holds your application together.The controllers contain the code that responds to user requests through the web browser.

Metaprogramming


One of the reasons that it is sometimes difficult to tell Ruby and Ruby on Rails apart is that Rails uses a technique called metaprogramming to create what is known as a domain-specific language (DSL). A DSL is a programming language that is designed to solve problems in a specific domain. In this case, web applications are the domain, and Rails is a language that helps you describe your problem within this domain.
The ORM ActiveRecord (as described in the “Models: ActionRecord” section) provides a DSL for accessing your data, which means that we can use commands like
find_user_by_username('alan') instead of having to go through lengthy sections of code that connect to a database, perform a SQL query, and then process the results. As you start writing applications using ActiveRecord finder methods, you will find it increasingly difficult to go back to writing SQL by hand.Ruby makes it easy to create DSLs. As your Ruby skills improve, you should find yourself starting to think about how you can develop your application to best use the concept of DSLs.This will lead you to extend the feature set of Rails to enable it to work better within your application domain.

Built-in Testing

When developing web applications, testing the application often gets left to the end of the project or not given the amount of time or respect that it deserves. Often, the reason for this is that developing tests for the application may be difficult or time consuming.
The Rails framework comes complete with integrated automated testing tools. These tools make it incredibly simple to write unit, functional, and integration tests. Because writing the tests is so simple, you will find it makes sense to write the tests at the same time that you develop your code.