0
Ruby On Rails… Siddhesh Bhobe
What is Ruby? <ul><li>An OO language! </li></ul><ul><li>… successfully combines Smalltalk's conceptual elegance, Python's ...
What is Rails? <ul><li>Rails is an open source Ruby framework for developing database-backed web applications </li></ul><u...
Why the hell do we need another language and another framework???
Well… What if you could develop a web application  at least  ten times faster with Rails?
Let’s start with a demo…
Demo Steps <ul><li>Install Instant Rails which includes Rails, MySQL and an in-built web server – directory copy, no insta...
The Project Hierarchy – Convention over Configuration
Main Modules of a Rails Application <ul><li>The  controllers  subdirectory is where Rails looks to find controller classes...
Notes <ul><li>The “scaffold” provides basic CRUD functionality, as well as basic views for the data – this can be overridd...
Overriding Scaffold Methods <ul><li>Define your method (say, for the list functionality) in the controller  </li></ul>
Overriding Scaffold Methods <ul><li>Provide your own list.rhtml - simply an html file with Ruby code embedded within <% %>...
And We Get..
Setting Relationships between Model Objects <ul><li>Class Recipe < ActiveRecord::Base </li></ul><ul><li>belongs_to :catego...
Use Layouts <ul><li>Provides common header/footer for all pages </li></ul><ul><li>Actual content goes in place of @content...
And We Get…
Hey, but this was too simple an application! Does it do anything serious?
Some Real Applications <ul><li>Basecamp  is a web-based tool that lets you manage projects (or simply ideas) and quickly c...
Some Real Applications <ul><li>43 Things  is a goal-setting social software web application. It currently has 6,000 regist...
Some Real Applications <ul><li>Ta- da  Lists  is a free online service that implements simple, sharable to-do lists. It fe...
And More.. <ul><li>Check out the screencasts at </li></ul><ul><li>http://www.rubyonrails.org/screencasts </li></ul>
Cool Rails Features <ul><li>Caching </li></ul><ul><ul><li>Page (as HTML), Action (Similar to Page, but applies filters lik...
Ajax on Rails <ul><li>Ajax (Asynchronous JavaScript and XML) works on top of  XMLHttpRequest   </li></ul><ul><li>Ajax (thr...
How it Works in Rails <ul><li>A trigger action occurs. This could be the user clicking on a button or link, the user makin...
A Sample View File
The Corresponding Controller
And You Get…
References <ul><li>Article on which this presentation is based:  http://instantrails.rubyforge.org/tutorial/index.html </l...
Upcoming SlideShare
Loading in...5
×

Ruby On Rails Siddhesh

721

Published on

Introduction to Ruby on Rails

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
721
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Ruby On Rails Siddhesh"

  1. 1. Ruby On Rails… Siddhesh Bhobe
  2. 2. What is Ruby? <ul><li>An OO language! </li></ul><ul><li>… successfully combines Smalltalk's conceptual elegance, Python's ease of use and learning, and Perl's pragmatism… </li></ul><ul><li>… originated in Japan in the early 1990s </li></ul>
  3. 3. What is Rails? <ul><li>Rails is an open source Ruby framework for developing database-backed web applications </li></ul><ul><li>Rail's guiding principles: </li></ul><ul><ul><li>less software and </li></ul></ul><ul><ul><li>convention over configuration </li></ul></ul>
  4. 4. Why the hell do we need another language and another framework???
  5. 5. Well… What if you could develop a web application at least ten times faster with Rails?
  6. 6. Let’s start with a demo…
  7. 7. Demo Steps <ul><li>Install Instant Rails which includes Rails, MySQL and an in-built web server – directory copy, no installation required </li></ul><ul><li>Create a Rails project </li></ul><ul><li>Create a database with sample table </li></ul><ul><li>Generate the model and controller in Rails </li></ul><ul><li>Provide CRUD functionality for the table on the web </li></ul><ul><li>IN TEN MINUTES </li></ul><ul><li>Check http://instantrails.rubyforge.org/tutorial/index.html to try this on your own! </li></ul>
  8. 8. The Project Hierarchy – Convention over Configuration
  9. 9. Main Modules of a Rails Application <ul><li>The controllers subdirectory is where Rails looks to find controller classes. A controller handles a web request from the user. </li></ul><ul><li>The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser. </li></ul><ul><li>The models subdirectory holds the classes that model and wrap the data stored in our application's database. </li></ul><ul><li>The helpers subdirectory holds any helper classes used to assist the model, view, and controller classes. </li></ul>
  10. 10. Notes <ul><li>The “scaffold” provides basic CRUD functionality, as well as basic views for the data – this can be overridden by you </li></ul><ul><li>URLs are simple and straightforward </li></ul><ul><li>Smartly maps models to table names - Recipe to recipes, Person to people and Country to countries  </li></ul>
  11. 11. Overriding Scaffold Methods <ul><li>Define your method (say, for the list functionality) in the controller </li></ul>
  12. 12. Overriding Scaffold Methods <ul><li>Provide your own list.rhtml - simply an html file with Ruby code embedded within <% %> and <%= %> tags </li></ul>
  13. 13. And We Get..
  14. 14. Setting Relationships between Model Objects <ul><li>Class Recipe < ActiveRecord::Base </li></ul><ul><li>belongs_to :category </li></ul><ul><li>End </li></ul><ul><li>Class Category < ActiveRecord::Base </li></ul><ul><li>has_many :recipes </li></ul><ul><li>end </li></ul>
  15. 15. Use Layouts <ul><li>Provides common header/footer for all pages </li></ul><ul><li>Actual content goes in place of @content_for_layout </li></ul>
  16. 16. And We Get…
  17. 17. Hey, but this was too simple an application! Does it do anything serious?
  18. 18. Some Real Applications <ul><li>Basecamp is a web-based tool that lets you manage projects (or simply ideas) and quickly create client/project extranets. It lets you and your clients (or just your own internal team) keep your conversations, ideas, schedules, to-do lists, and more in a password-protected central location. </li></ul><ul><li>http://www.basecamphq.com/ </li></ul>
  19. 19. Some Real Applications <ul><li>43 Things is a goal-setting social software web application. It currently has 6,000 registered users and hundreds of thousands of unregistered visitors. 43 Things has 4,500 lines of code that were developed in three months by three full-time developers. </li></ul><ul><li>http://www.43things.com/ </li></ul>
  20. 20. Some Real Applications <ul><li>Ta- da Lists is a free online service that implements simple, sharable to-do lists. It features a highly responsive user interface that uses XMLHttpRequest to minimize waiting for the server. Ta-da Lists came from one developer using one week of development time producing 579 lines of code. </li></ul><ul><li>http://www.tadalist.com/ </li></ul>
  21. 21. And More.. <ul><li>Check out the screencasts at </li></ul><ul><li>http://www.rubyonrails.org/screencasts </li></ul>
  22. 22. Cool Rails Features <ul><li>Caching </li></ul><ul><ul><li>Page (as HTML), Action (Similar to Page, but applies filters like authentication), Fragment </li></ul></ul><ul><ul><li>Caches calculations, renderings and database calls </li></ul></ul><ul><ul><li>Sweeper – cleans the cache based on changes to the model objects </li></ul></ul><ul><li>Data Validation </li></ul><ul><li>validates_length_of :category, :within => 1..20 </li></ul><ul><li>Callbacks (like before and after triggers) – very useful for cache sweeping, for example </li></ul><ul><li>Transactions – save and destroy are already covered </li></ul><ul><li>Custom Code Generators </li></ul>
  23. 23. Ajax on Rails <ul><li>Ajax (Asynchronous JavaScript and XML) works on top of XMLHttpRequest </li></ul><ul><li>Ajax (through XMLHttpRequest) lets browser-side JavaScript communicate with the web server in the background without requiring the browser to display a new web page </li></ul><ul><li>Libraries like DWR and Ajax.NET provide high-level services for Ajax that hide browser-specific differences </li></ul><ul><li>Rails has built-in support for Ajax </li></ul>
  24. 24. How it Works in Rails <ul><li>A trigger action occurs. This could be the user clicking on a button or link, the user making changes to the data on a form or in a field, or just a periodic trigger. </li></ul><ul><li>Data associated with the trigger (a field or an entire form) is sent asynchronously to an action handler on the server via XMLHttpRequest. </li></ul><ul><li>The server-side action handler takes some action based on the data, and returns an HTML fragment as its response. </li></ul><ul><li>The client-side JavaScript (created automatically by Rails) receives the HTML fragment and uses it to update a specified part of the current page's HTML, often the content of a <div> tag. </li></ul>
  25. 25. A Sample View File
  26. 26. The Corresponding Controller
  27. 27. And You Get…
  28. 28. References <ul><li>Article on which this presentation is based: http://instantrails.rubyforge.org/tutorial/index.html </li></ul><ul><li>Ruby Homepage: </li></ul><ul><li>http://www.ruby-lang.org/en/ </li></ul><ul><li>Ruby on Rails Homepage: </li></ul><ul><li>http://www.rubyonrails.com/ </li></ul><ul><li>Four Days on Rails (great to start with): </li></ul><ul><li>http://rails.homelinux.org/ </li></ul><ul><li>Ruby on Rails How Tos: </li></ul><ul><li>http://wiki.rubyonrails.com/rails/pages/Howtos </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×