Skip to main content

Ruby on Rails Tutorial

Ruby on Rails Introduction 

Hi all I,m here with a new article actually It's trending laguage for you all .Invented in Japan.
That means it's very active language.
Also it's  need some theory parts to understand these things very well so i will go through by explaining them simply.

What is Ruby?
Before we Ride on Rails , let us recapitulate a few points of ruby, which is the base of Rails.

Ruby is the successful combination of

  • Smalltalk's conceptual elegance
  • python's ease of use and learning and
  • perl's pragmatism

Ruby is  
  • A high level programming language.
  • Interpreted like Perl, Python , Tcl/Tk.
  • Object oriented like Smalltalk, Eiffel, Ada ,Java
Why Ruby?
Ruby originated in japan and now it is gaining popularity in US and Europe  as well. The following factors contribute towards  its popularity.

  • Easy to learn
  • Open source(very liberal license)
  • rich libraries
  • very easy to extend 
  • Truly Object Oriented
  • Less coding with fewer bugs 
  • Helpful Community

Although we have many reasons to use ruby, there are a few drawbacks as well that you may to consider before implementing Ruby

Performance issues 

Although it rivals Perl and Python, it is an interpreted language and we cannot compare it with high level programming language like C or C++.

Threading model

Ruby does not use native threads.Ruby threads are simulated in the VM rather than running as native OS threads.

Here is a Sample Ruby Code to Print hello ruby 

Embedded Ruby

Ruby provides a program called ERB.(Embedded Ruby), written by Seki Masatoshi. ERB allows you to put Ruby codes inside an HTML file. ERB reads along, word for word, and then at a certain point, when it encounters a Ruby code embedded in the document, it starts executing the Ruby Code.

You need to know only two things to prepare an ERB document-

  • If you want some Ruby code executed, enclose it between <%and%>
  • If you want the result of the code execution to be printed out as a part of the output enclose the code between  <%=and%>
Here's an example 
Save the following code in erbdemo.rb file .Note that a Ruby file will have an extension .rb

<% page_title ="Demonstration of ERB" %>
<%salutation= "Dear programmer." %>

Now,run the program using the command line utility erb.

tp> erb erbddemo .rb


This will produce the following result

What is Rails?

  • An extremely productive web application framework.
  • Written in Ruby by David Heinemeier Hansson.
  • You could develop a web application at least ten times faster with rails than you could with a typical Java framework 
  • an opensource Ruby framework for developing database backed web applications.
  • Configure your code with Database Schema
  • No compilation phase required.
Full Stack Framework

  • Includes everything needed to create a databse driven web application, using the Model View Controller Pattern.
  • Being a fullstack framework means all the layers are built to work seamlessly together with less code.
  • Requires fewer lines of code than other frameworks.
Convention over Configuration 

 Rails shuns configuration files in favor of conventions, reflections, and dynamic run time extensions.
Your application code and your running database already contain  everything that Rails needs to know.

Rails Strengths

 Rails is packed with features that make you more productive, with many of the following features building on one other.

Meta programming

Where other framework use extensive code generation from scratch ,rail framework uses  MetaProgramming techniques to write programs. Ruby is one of the best languages  for Metaprogramming. and Rails uses this capability well. Rails also uses code generation but relies much more on MetaProgramming for the heavy lifting. 


Active Record

Rails introduces the Active Record framework, which saves objects into the database. The Rails version of the Active record discovers the columns in a database schema and automatically attaches them to your domain objects using meta-programming.

Convention over configuration

Most web development frameworks  for .NET or JAVA force you to write pages of configuration code. If you follow the suggested naming conventions , Rails doesn't need much configuration. 

Scaffolding

 You often create temporary code in the early stages of development to help get an application up quickly and see how major components work together.Rails automatically creates  much more scaffolding you will need.

Built in testing

 Rails creates simple automated tests you can then extend. Rails also provides supporting code called "harnesses and fixtures" that make test cases easier to write and run.Ruby can then execute all your automated  tests with the rake utility.

Three environments

Rails gives you three default environments-
development ,testing, and production. Each behaves slightly differently , making your entire software development cycle easier. For example , Rails creates a fresh copy of the Test database  for each test run.


All right folks that's it for today !!!

It's not over My self just touch on Ruby and Rails You have dive in and find interesting.

I,m telling you for sure this is one of the easiest languages I have ever seen so try on It's very Interesting

Comments

Popular posts from this blog

Data Compression- Run Length Encoding

Hello Again!! This article is beyond from the programming. FYI as a programmer you should have a knowledge about these things. If not you will ended up with a mess. It's RLE What is it?  Run Length Encoding is a very simple form of loosless data compression in which runs of data are stored as a single data value and count, rather than as the original run. Understood? I bet you wont !! Let me go it with my way right after this article you will a have sufficient knowledge about RLE for sure. Let's Dive in ! Let's try an encoding image drawn using three colors on a 5x5 grid. First we will use simple method We have assigned a letter to each of the colors, Y for Yellow, G for Green, and B for Blue. As a result of transforming the rows into Ys,Gs nad Bs one line at a time starting from the upper left, we were able to encode the figure into a line of 25 letters. Next, using run legth encoding on the image, let's try expressing it in less than 25 le...

Quick Tutorial with Pedometer

For a better start i'm gonna go through some points Arduino uno(with connecting cable) Accelerometer Jumper Cables Bouth & Pb (since i,m a chemistry student)                                                               Ok here we go!  I hope you all familiar with what above mention with the points. If not quickly follow me whatever the social media i mentioned in my blog i'm willing to help you. First of all i would like to introduce Arduino Uno here. This is a simple picture of it. as i mention in the picture arduino uno consists with digital pins & power pins. Accelerometer is the sensor what we going to work with now.It will look like this.     in this picture it's just a sensor with holes. to fill with that up you gonna need headers(male/female). Probably now you need your bo...