Saturday, 28 April 2012

What is Rails or about Rails

Ok... I guess now you are ok with  Ruby(I will give more details on Ruby, but I want to go parallel with Rails so that you people can have good experience) and want to go ahead with Rails... Why Rails??? Because Ruby On Rails(RoR) is more famous because of web application and for that you need to know the heart of it YES it is RAILS. Rails is actually a framework, which is written in Ruby language created  by David Heinemeier Hansson- from his work on Basecamp(a project management tool)

Few things which Rails follows - 

1. DRY - Don’t Repeat Yourself - code should not be repeated - which inspires us for modular-ism.
2. Convention over configuration - Rails makes the assumption about your requirement and process rather than specifying each thing.
3. REST is the best architecture for web application.

Now if you want to know Rails more you have to know three things 
A. about MVC structure. 
B. Components of Rails
C. REST

A. What is MVC?
Rails follow this Model, View, Controller architecture, usually just called MVC.  Through this model 
1. we can isolate business logic from the user interface, 
2. helps to keep code dry & 
3. helps for maintenance for different types of code.

A model generally handles all the database related and business logic related issues/code. Normally Most of the code is being written here for applications. It is the HEART of MVC architecture. Model takes request from controller & after executing that request sends back the control to controller. It represent the information/data of the application and the rules to manipulate that data. Its main task is to manage the rules of interaction with a corresponding database table. Each table in your database will correspond to one model in your application(though we can customize it). The bulk of your application’s business logic will be concentrated in the models. In the case of Rails, tables names comes with plural form of model name.
Views are the user interface of the application. In Rails, views are often HTML files with embedded Ruby code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application. It takes requests from user and request controller to perform the task and again render back the result to user.
Controllers are the middle man or the communicator between models and views. In Rails, controllers are responsible for processing the incoming requests from views i.e the web browser, interrogating the models for data, and passing that data on to the views for presentation.




B.Now think that Rails is a country which has so many islands  i.e components.


 The islands of Rails are 


  • 1. Action Pack(Action Controller + Action Dispatch + Action View)
  • 2. Action Mailer
  • 3. Active Model
  • 4. Active Record
  • 5. Active Resource
  • 6. Active Support
  • 7. Railties
C. REST
  • Using resource identifiers such as URLs to represent resources.
  • Transferring representations of the state of that resource between system components.


Here is a brief about Rails components:-
A single gem "Action Pack" contains Action Controller, Action View and Action Dispatch. The 'View-Controller' part of 'Model-View-Controller'.
In Rails application(app.) Action Controller manages the controllers. It is a framework which processes incoming requests to app., extracts parameters, and dispatches them to the intended action. Its main task is to session management, template rendering, and redirect management.
Action View manages the user interface/views of the app. It can create both HTML and XML output by default. Its main task is rendering templates, including nested and partial templates, and also built-in AJAX support. 
Action Dispatch manages routing of web requests and dispatches them as your requirement, it can be done for both/either to your application or any other Rack application.
Action Mailer framework provides us e-mail services. To receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates - we use it.
Active Model is the key to define interface between the Action Pack gem services and Object Relationship Mapping(ORM) gems like Active Record. You also can utilize other ORMframeworks in place of Active Record if your application needs this via active model.
Active Record is the heart for the models in a Rails application. It gives us database independence, basic CRUD functionality, advanced finding capabilities, and the ability to relate models to one another, among other services.
Active Resource framework to managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUDsemantics.
Active Support is an huge collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
Railties is the core Rails code that builds new Rails applications and communicate among the various frameworks and plugins together in any Rails application.
REST stands for Representational State Transfer and is the foundation of the RESTful architecture. We got it from Roy Fielding’s doctoral thesis, which comes to two main principles:
For example, the following HTTP request:
UPDATE/books/58
would be understood to refer to a book resource with the ID of 58, and to indicate a desired action – updating that resource. REST is a natural style for the architecture of web applications, and Rails provides this shielding to you from many of the RESTful complexities and browser quirks.




Thanks to(official sites of...) => Ruby guide & Rails Casts & Ruby About & Wikipedia And RubyOnRails

Sunday, 22 April 2012

What is Ruby language? Or about Ruby Or Ruby Features...

Ruby is a scripting language created by Yukihiro “matz” Matsumoto(Japanese) in 1993, inspired from Perl, Smalltalk, Eiffel, Ada, and Lisp. Almost all of the good things from above mentioned languages are present here to minimize the effort of coding and also to reduce frustration.


Some features of Ruby(about Ruby):


1. Its a pure object oriented language with almost 45 keywords -  what ever you will write/see in ruby code is an object except argument list(whenever you are passing parameters) and control flow syntax like if, rescue, begin, end, class, alias etc.
2. It does not support multiple inheritance, but gave us 'MIXIN' - to include modules in classes, then we can access any of the methods of the said module.
3. Its a portable, cross platform & interpreted language.
4.  Its flexible - as it is open source we can redefine it as our own interest. In terms of coding also its provides us a high level flexibility - we can extend a class even it could be a basic method/class(Ex we can redefine integer or string) which we can alter or can add our own lines of code through 'block' we can add closure to any methods we have defined previously(classes are open). 
5. We can write multiple lines of code in a single line with statement delimiters and gives us open ground to write our code as we wish in our own format (no need to start from a specific line/column like few other languages) but it case sensitive
6. Its gives a excellent way to error handling like java and has its own garbage collection which is maintained automatically- though we can do it manually too.
7. Another very important thing is Ruby provides a OS independent threading even if the OS does not support threading still Ruby can handle it.
8. Untyped or loosely typed - we don't need to declare any variable type but can store any value directly.
9. Access modifier continues until the end of the scope, or until another access modifier pops up, whichever comes first. By default, methods are public. In Ruby,public is, naturally, public. private means the method(s) are accessible only when they can be called without an explicit receiver. Only self is allowed to be the receiver of a private method call.
protected is the one to be on the lookout for. A protected method can be called from a class or descendant class instances, but also with another instance as its receiver.10. Its gave us singleton method and a special method for missing method named method_missing.
11. A method call is like a message passing than function calling.
12. And lastly IT IS FREE yes... it is free so no extra licensing cost is there. 


These are gist only. If you have any quarries or any doubt feel free to post. 


Please also post your quarries here... it is not mandatory to be related to above topics. :) :p ....

Wednesday, 18 April 2012

10 most important site for any RoR professional

I thought to start blogging with some pattern, but then I thought I should dedicate my first blog post to those from where I started learning.... Here is the list of sites from where anybody can find out the most appropriate solutions/answer for Ruby On Rails problems
1. http://guides.rubyonrails.org/
2. http://www.ruby-lang.org/en/
3. http://www.rubyist.net/~slagell/ruby/index.html
4. http://www.ruby-doc.org/docs.
5. http://api.rubyonrails.org/
6. www.railscasts.com/
7. www.github.com
8. http://rubyforge.org/
9. http://rubygems.org/gems/rubyforge
10. http://beginrescueend.com/

DO NOT Forget peepcode also....

Please post your feedbacks/suggestions/questions and doubt here....