SlideShare a Scribd company logo
1 of 20
Download to read offline
Ruby On Rails
       Basics

      Amit Solanki
 http://amitsolanki.com
Introduction



Web-application framework - includes everything needed to create
database-backed web applications according to the Model-View-
Control(MVC) pattern
Built on Ruby - Language of the year 2006
Extracted by David Heinemeier Hansson(DHH) from his work on
Basecamp, a project management tool by 37signals
Released as open source in July 2004 - more than 1400 contributors
Showcase
More at http://rubyonrails.org/applications
Framework - Why do we need it?

Consider following Python Code:
#!/usr/bin/env python


import MySQLdb


print "Content-Type: text/htmln"
print "<html><head><title>Books</title></head>"
print "<body>"
print "<h1>Books</h1>"
print "<ul>"


connection = MySQLdb.connect(user='mysql_user', passwd='mysql_pass', db='my_database')
cursor = connection.cursor()
cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10")


for row in cursor.fetchall():
  print "<li>%s</li>" % row[0]


print "</ul>"
print "</body></html>"


connection.close()
Framework - Why do we need it?
What happens when multiple parts of your application need to connect to the
database?
-     database-connecting code need to be duplicated in each individual CGI script.
      Instead, we could refactor it into a shared function
Should a developer really have to worry about printing the “Content-Type”
line and remembering to close the database connection?
-     this reduces programmer productivity and introduces opportunities for mistakes. These
      setup- and teardown-related tasks would best be handled by some common
      infrastructure

What happens when this code is reused in multiple environments, each with a
separate database and password?
-    some environment-specific configuration becomes essential

What happens when a Web designer who has no experience coding Python
wishes to redesign the page?
-    one wrong character could crash the entire application. Ideally, the logic of the page — the
      retrieval of book titles from the database — would be separate from the HTML display of
      the page, so that a designer could edit the latter without affecting the former.
Framework - Why do we need it?
The MVC Implementation:
 # models.py (the database tables)
 from django.db import models
 class Book(models.Model):
     name = models.CharField(max_length=50)
     pub_date = models.DateField()

 # views.py (the business logic)
 from django.shortcuts import render_to_response
 from models import Book
 def latest_books(request):
     book_list = Book.objects.order_by('-pub_date')[:10]
     return render_to_response('latest_books.html', {'book_list': book_list})

 # urls.py (the URL configuration)
 from django.conf.urls.defaults import *
 import views
 urlpatterns = patterns('',
     (r'^latest/$', views.latest_books),
 )

 # latest_books.html (the template)
 <html><head><title>Books</title></head>
 <body>
 <h1>Books</h1>
 <ul>
 {% for book in book_list %}
 <li>{{ book.name }}</li>
 {% endfor %}
 </ul>
 </body></html>
Framework - Why do we need it?

The models.py file contains a description of the database table, represented by
a Python class. This class is called a model. Using it, you can create, retrieve,
update and delete records in your database using simple Python code rather
than writing repetitive SQL statements
The views.py file contains the business logic for the page. The latest_books()
function is called a view
The urls.py file specifies which view is called for a given URL pattern. In this
case, the URL /latest/ will be handled by the latest_books() function. In other
words, if your domain is example.com, any visit to the URL http://
example.com/latest/ will call the latest_books() function
The latest_books.html file is an HTML template that describes the design of
the page. It uses a template language with basic logic statements — e.g., {%
for book in book_list %}
Running Rails on your machine

Install ruby - http://ruby-lang.org/
    Windows: One click installer
    Linux: Installer tools such as apt-get and yum
    Mac OS X: Macports
    Best practice is to install by compiling from source
Install rubygems - http://rubyforge.org
Install rails gem - http://rubyonrails.org/download
    gem install rails
    may require sudo access on unix/linux based OS
Editors: TextMate, VIM, Emacs, jEdit, SciTE
IDE: RadRails, RubyMine, 3rd Rail, NetBeans, Komodo
Features

Convention over Configuration
Don't Repeat Yourself (DRY)
Agile
    Individuals and interactions over processes and tools
    Working software over comprehensive documentation
    Customer collaboration over contract negotiation
    Responding to change over following a plan
Easy integration with features with AJAX and RESTful
Connects to most of the databases - just install DB driver
Latest stable release is 2.3 => 3.0 Coming soon
Rails is FUN
Model-View-Controller Architecture


        1      Controller


    4          3            2


        View            Model    Database   1
Framework Structure
ActiveRecord
    an object relationship mapping (ORM) system for database access
ActiveResource
    provides web services
    before 2.0 => ActionWeb
ActionPack
    ActionController
    ActionView
ActiveSupport
    Utility classes and standard library extensions from Rails
ActionMailer
Plugins to extend capability
Directory Structure
     .
     |-- README                 Installation and usage information
     |-- Rakefile               Build script
     |-- app                    Model, view and controller files go here
     | |-- controllers
     | |-- helpers
     | |-- models
     | |-- views
     |-- config                 Configuration and database connection parameters
     | |-- boot.rb
     | |-- database.yml
     | |-- environment.rb
     | |-- environments
     | |-- initializers
     | `-- routes.rb
     |-- db                     Schema and migration information
     | |-- migrate
     |-- doc                    Autogenerated documentation
     |-- lib                    Shared code
     |-- log                    Log files produced by your application
     |-- public                 Web-acccessible directory. Your application runs from here
     |-- script                 Utility scripts
     |-- test                   Unit, functional, and integration tests, fixtures, and mocks
     |-- tmp                    Runtime temporary files
     |-- vendor Imported code
       `-- plugins
Demo
config/

Every environment has a database configuration in database.yml
Global configuration file - environment.rb
Individual configuration file under config/environments
    production.rb
    development.rb
    test.rb
Easy to add custom environments
    e.g. for a staging server create staging.rb
Start server by passing RAILS_ENV
    ruby script/server RAILS_ENV=‘production’
    mongrel_rails start
script/


 about
 breakpointer
 console
 dbconsole
 destroy
 generate
 plugin
 runner
 server
Rake


db:migrate
doc:app
doc:rails
log:clear
rails:freeze:gems
rails:freeze:edge
rails:update
test
stats
Some Quotes
“Rails is the most well thought-out web development framework I’ve ever used.
And that’s in a decade of doing web applications for a living. I’ve built my
own frameworks, helped develop the Servlet API, and have created more than a
few web servers from scratch. Nobody has done it like this before.”
-James Duncan Davidson, Creator of Tomcat and Ant
“Ruby on Rails is a breakthrough in lowering the barriers of entry to
programming. Powerful web applications that formerly might have taken
weeks or months to develop can be produced in a matter of days.”
-Tim O'Reilly, Founder of O'Reilly Media
“It is impossible not to notice Ruby on Rails. It has had a huge effect both in
and outside the Ruby community... Rails has become a standard to which
even well-established tools are comparing themselves to.”
-Martin Fowler, Author of Refactoring, PoEAA, XP Explained
“What sets this framework apart from all of the others is the preference for
convention over configuration making applications easier to develop and
understand.”
-Sam Ruby, ASF board of directors
Some Quotes (contd.)

“Before Ruby on Rails, web programming required a lot of verbiage, steps and
time. Now, web designers and software engineers can develop a website much
faster and more simply, enabling them to be more productive and effective in
their work.”
-Bruce Perens, Open Source Luminary
“After researching the market, Ruby on Rails stood out as the best choice. We
have been very happy with that decision. We will continue building on Rails
and consider it a key business advantage.”
-Evan Williams, Creator of Blogger, ODEO, and Twitter
“Ruby on Rails is astounding. Using it is like watching a kung-fu movie,
where a dozen bad-ass frameworks prepare to beat up the little newcomer only
to be handed their asses in a variety of imaginative ways.”
-Nathan Torkington, O'Reilly Program Chair for OSCON
“Rails is the killer app for Ruby.”
Yukihiro Matsumoto, Creator of Ruby
Resources

guides.rubyonrails.org
weblog.rubyonrails.com
loudthinking.com
rubyinside.com
therailsway.com
weblog.jamisbuck.com
errtheblog.com
nubyonrails.com
planetrubyonrails.org
blog.caboo.se
Thanks
Amit Solanki
amit@vinsol.com

More Related Content

What's hot

Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design PatternsBobby Bouwmann
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS IntrodructionDavid Ličen
 
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL ShellMySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL ShellMiguel Araújo
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAvasuraj pandey
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3 ArezooKmn
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentationscandiweb
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaEdureka!
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXLRob Gietema
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Mydbops
 

What's hot (20)

Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL ShellMySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Jdbc_ravi_2016
Jdbc_ravi_2016Jdbc_ravi_2016
Jdbc_ravi_2016
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Xampp installation
Xampp installation Xampp installation
Xampp installation
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentation
 
Struts
StrutsStruts
Struts
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
 
Corso js and angular
Corso js and angularCorso js and angular
Corso js and angular
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp element
Jsp elementJsp element
Jsp element
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 

Similar to Ruby On Rails Basics

Ruby Rails Web Development
Ruby Rails Web DevelopmentRuby Rails Web Development
Ruby Rails Web DevelopmentSonia Simi
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arpGary Pedretti
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On RailsDavid Keener
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails SiddheshSiddhesh Bhobe
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Ido Flatow
 
Rails
RailsRails
RailsSHC
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaJason Noble
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupJose de Leon
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginnerUmair Amjad
 
Getting Started with MariaDB with Docker
Getting Started with MariaDB with DockerGetting Started with MariaDB with Docker
Getting Started with MariaDB with DockerMariaDB plc
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkEdureka!
 

Similar to Ruby On Rails Basics (20)

Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Ruby Rails Web Development
Ruby Rails Web DevelopmentRuby Rails Web Development
Ruby Rails Web Development
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On Rails
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6
 
Rails
RailsRails
Rails
 
Ruby on rails for beginers
Ruby on rails for beginersRuby on rails for beginers
Ruby on rails for beginers
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp Atlanta
 
RoR guide_p1
RoR guide_p1RoR guide_p1
RoR guide_p1
 
Ruby on rails RAD
Ruby on rails RADRuby on rails RAD
Ruby on rails RAD
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User Group
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginner
 
Getting Started with MariaDB with Docker
Getting Started with MariaDB with DockerGetting Started with MariaDB with Docker
Getting Started with MariaDB with Docker
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails Framework
 
Intro lift
Intro liftIntro lift
Intro lift
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 

Recently uploaded

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Ruby On Rails Basics

  • 1. Ruby On Rails Basics Amit Solanki http://amitsolanki.com
  • 2. Introduction Web-application framework - includes everything needed to create database-backed web applications according to the Model-View- Control(MVC) pattern Built on Ruby - Language of the year 2006 Extracted by David Heinemeier Hansson(DHH) from his work on Basecamp, a project management tool by 37signals Released as open source in July 2004 - more than 1400 contributors
  • 4. Framework - Why do we need it? Consider following Python Code: #!/usr/bin/env python import MySQLdb print "Content-Type: text/htmln" print "<html><head><title>Books</title></head>" print "<body>" print "<h1>Books</h1>" print "<ul>" connection = MySQLdb.connect(user='mysql_user', passwd='mysql_pass', db='my_database') cursor = connection.cursor() cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10") for row in cursor.fetchall(): print "<li>%s</li>" % row[0] print "</ul>" print "</body></html>" connection.close()
  • 5. Framework - Why do we need it? What happens when multiple parts of your application need to connect to the database? - database-connecting code need to be duplicated in each individual CGI script. Instead, we could refactor it into a shared function Should a developer really have to worry about printing the “Content-Type” line and remembering to close the database connection? - this reduces programmer productivity and introduces opportunities for mistakes. These setup- and teardown-related tasks would best be handled by some common infrastructure What happens when this code is reused in multiple environments, each with a separate database and password? - some environment-specific configuration becomes essential What happens when a Web designer who has no experience coding Python wishes to redesign the page? - one wrong character could crash the entire application. Ideally, the logic of the page — the retrieval of book titles from the database — would be separate from the HTML display of the page, so that a designer could edit the latter without affecting the former.
  • 6. Framework - Why do we need it? The MVC Implementation: # models.py (the database tables) from django.db import models class Book(models.Model): name = models.CharField(max_length=50) pub_date = models.DateField() # views.py (the business logic) from django.shortcuts import render_to_response from models import Book def latest_books(request): book_list = Book.objects.order_by('-pub_date')[:10] return render_to_response('latest_books.html', {'book_list': book_list}) # urls.py (the URL configuration) from django.conf.urls.defaults import * import views urlpatterns = patterns('', (r'^latest/$', views.latest_books), ) # latest_books.html (the template) <html><head><title>Books</title></head> <body> <h1>Books</h1> <ul> {% for book in book_list %} <li>{{ book.name }}</li> {% endfor %} </ul> </body></html>
  • 7. Framework - Why do we need it? The models.py file contains a description of the database table, represented by a Python class. This class is called a model. Using it, you can create, retrieve, update and delete records in your database using simple Python code rather than writing repetitive SQL statements The views.py file contains the business logic for the page. The latest_books() function is called a view The urls.py file specifies which view is called for a given URL pattern. In this case, the URL /latest/ will be handled by the latest_books() function. In other words, if your domain is example.com, any visit to the URL http:// example.com/latest/ will call the latest_books() function The latest_books.html file is an HTML template that describes the design of the page. It uses a template language with basic logic statements — e.g., {% for book in book_list %}
  • 8. Running Rails on your machine Install ruby - http://ruby-lang.org/ Windows: One click installer Linux: Installer tools such as apt-get and yum Mac OS X: Macports Best practice is to install by compiling from source Install rubygems - http://rubyforge.org Install rails gem - http://rubyonrails.org/download gem install rails may require sudo access on unix/linux based OS Editors: TextMate, VIM, Emacs, jEdit, SciTE IDE: RadRails, RubyMine, 3rd Rail, NetBeans, Komodo
  • 9. Features Convention over Configuration Don't Repeat Yourself (DRY) Agile Individuals and interactions over processes and tools Working software over comprehensive documentation Customer collaboration over contract negotiation Responding to change over following a plan Easy integration with features with AJAX and RESTful Connects to most of the databases - just install DB driver Latest stable release is 2.3 => 3.0 Coming soon Rails is FUN
  • 10. Model-View-Controller Architecture 1 Controller 4 3 2 View Model Database 1
  • 11. Framework Structure ActiveRecord an object relationship mapping (ORM) system for database access ActiveResource provides web services before 2.0 => ActionWeb ActionPack ActionController ActionView ActiveSupport Utility classes and standard library extensions from Rails ActionMailer Plugins to extend capability
  • 12. Directory Structure . |-- README Installation and usage information |-- Rakefile Build script |-- app Model, view and controller files go here | |-- controllers | |-- helpers | |-- models | |-- views |-- config Configuration and database connection parameters | |-- boot.rb | |-- database.yml | |-- environment.rb | |-- environments | |-- initializers | `-- routes.rb |-- db Schema and migration information | |-- migrate |-- doc Autogenerated documentation |-- lib Shared code |-- log Log files produced by your application |-- public Web-acccessible directory. Your application runs from here |-- script Utility scripts |-- test Unit, functional, and integration tests, fixtures, and mocks |-- tmp Runtime temporary files |-- vendor Imported code `-- plugins
  • 13. Demo
  • 14. config/ Every environment has a database configuration in database.yml Global configuration file - environment.rb Individual configuration file under config/environments production.rb development.rb test.rb Easy to add custom environments e.g. for a staging server create staging.rb Start server by passing RAILS_ENV ruby script/server RAILS_ENV=‘production’ mongrel_rails start
  • 15. script/ about breakpointer console dbconsole destroy generate plugin runner server
  • 17. Some Quotes “Rails is the most well thought-out web development framework I’ve ever used. And that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” -James Duncan Davidson, Creator of Tomcat and Ant “Ruby on Rails is a breakthrough in lowering the barriers of entry to programming. Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days.” -Tim O'Reilly, Founder of O'Reilly Media “It is impossible not to notice Ruby on Rails. It has had a huge effect both in and outside the Ruby community... Rails has become a standard to which even well-established tools are comparing themselves to.” -Martin Fowler, Author of Refactoring, PoEAA, XP Explained “What sets this framework apart from all of the others is the preference for convention over configuration making applications easier to develop and understand.” -Sam Ruby, ASF board of directors
  • 18. Some Quotes (contd.) “Before Ruby on Rails, web programming required a lot of verbiage, steps and time. Now, web designers and software engineers can develop a website much faster and more simply, enabling them to be more productive and effective in their work.” -Bruce Perens, Open Source Luminary “After researching the market, Ruby on Rails stood out as the best choice. We have been very happy with that decision. We will continue building on Rails and consider it a key business advantage.” -Evan Williams, Creator of Blogger, ODEO, and Twitter “Ruby on Rails is astounding. Using it is like watching a kung-fu movie, where a dozen bad-ass frameworks prepare to beat up the little newcomer only to be handed their asses in a variety of imaginative ways.” -Nathan Torkington, O'Reilly Program Chair for OSCON “Rails is the killer app for Ruby.” Yukihiro Matsumoto, Creator of Ruby