Your SlideShare is downloading. ×
  • Like
Ruby and Ruby­on­Rails
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ruby and Ruby­on­Rails



  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Ruby and Ruby­on­Rails 17th of November, 2007 Hyderabad, India
  • 2. We appreciate 
  • 3. Outline ● Ruby ● Ruby­on­Rails − Ruby­on­Rails: What is it? − MVC Pattern − Scaffolding − Active Record − Action View − Action Controller − Rails and Ajax
  • 4. Outline − Action Mailer − Web Service − IDE support ● Conclusion
  • 5. What is Ruby? ● Object­Oriented scripting language ● Conceptual similarities to Smalltalk ● Many system and text manipulation features like Perl ● Emphasis on simplicity and design elegance
  • 6. Ruby is a Dynamic Language ● Completely Object­Oriented − All data is an object, no exceptions − Operators are methods ● Dynamic Behavior − Possible to add new classes, add or redefine methods at  runtime − An instance of one class can behave differently than another  instance of the same class at runtime
  • 7. Powerful Features ● Single Inheritance, but… − Modules provide namespaces and allow ‘mixin’ capability − A module is a collection of methods and constants ● Ruby has blocks − Code surrounded by do…end or { … } − They are true closures; get variable bindings − Are passed to methods quite often
  • 8. More Language Features ● Portable − OS independent threading − Can load extension libraries dynamically ● Library support − RubyGems package manager − Tons of high­quality open source libraries available at RubyForge  (similar to CPAN for Perl)
  • 9. Ruby Tools The following tools are included with the Ruby distribution − debugger − irb – interactive ruby shell − benchmark − profiler − rdoc
  • 10. Ruby­on­Rails
  • 11. What Is Rails? Short Answer: − An extremely productive web application framework that is  written in Ruby by David Heinemeier Hansson. Long Answer: − Lets see the slides
  • 12. What Is Rails? Full Stack Framework − Includes everything needed to create a database­driven web  application using the Model­View­Controller pattern. − Being a full­stack framework means that all layers are built  to work seamlessly together. − That way you Don’t Repeat Yourself (DRY) Less Code − Requires fewer total lines of code than other frameworks  spend setting up their XML configuration files.
  • 13. What is Rails Convention over Configuration − Rails shuns configuration files in favor of conventions,  reflection and dynamic run­time extensions Configure your application by making it − Your code and database schema are the configuration! − No compilation phase ● Make a change, see it work.
  • 14. Model­View­Controller (MVC) 1 User Web browser 2 7 Views View Controller 5, 6 3, 4 Models Model end
  • 15. Rails Components ● Model − Active Record ­ SQL database access ● View − Action View ­ template rendering control − eRB ­ HTML templates − XML::Builder ­ XML templates ● Controller − Action Controller ­ request processing
  • 16. Rails Models ActiveRecord Model Classes − Encapsulate persistence logic − Contain business rules − Tightly coupled to database tables − Declare relationships to each other
  • 17. ActiveRecord Basics ● Extend ActiveRecord::Base ● Don’t declare properties ● Declare relationships to other models with the following ‘macros’ − belongs_to − has_many − has_and_belongs_to_many (joins)
  • 18. Rails Views User interface done with templates − HTML with Ruby snippets in .rhtml files − Easy XML generation in .rxml files − Lots of HTML and AJAX helper methods − Sophisticated layout and ‘partials’ functionality
  • 19. ERB Template Example
  • 20. Rails Controllers Process requests via action methods that map to URL − Interact with model classes − Set any data needed by view as field variables − Select view to render or redirect
  • 21. Controller Basics ● Extend ActionController:Base ● Request parameters in ‘params’ − Naming conventions mean Rails can translate paramaters  into a hashtable − Handles multi­dimensional data in forms pretty easily ● Web session in ‘session’ hash ● Redirect scope available in ‘flash’ hash for next request only
  • 22. AJAX <head> <%= javascript_include_tag :defaults %> </head> Inserts JavaScript AJAX libraries supplied with every Rails  application.  No additional scripting is necessary to use Rails  AJAX­based functions.
  • 23. AJAX Functions ● form_remote_tag / link_to_remote: Do an action with AJAX,  and put the response into a specified DOM element. ● observe_field / observe_form: Do an action with AJAX when a  field or form changes, and put the response into a DOM element. ● periodically_call_remote: Do an action at intervals.
  • 24. AJAX Functions 2 ● sortable_element: Make an element sortable by the user  and call an action when it changes. ● draggable_element / drop_receiving_element: Drag  and drop. ● visual_effect: Use in a callback to do fades, zooms, etc.
  • 25. AJAX Functions 3 ● :complete => evaluate_remote_response in your AJAX  call, and… ● update_javascript_function in your template to update  multiple elements with the return from a single AJAX call
  • 26. Web Services  RESTful Services − Uses HTTP itself as transport mechanism − respond_to helps to convert simple action methods to  RESTful action methods
  • 27. IDEs for Rails ● Eclipse − RadRails ● Netbeans − Netbeans 6 has in built support using JRuby ● CodeGear
  • 28. Summary / Take home Ruby is a Very High Level language that supports concepts such • as meta programming and reflection and makes using them natural instead of adopting a peripheral approach. Rails builds upon the simplicity, flexibility and power of Ruby to deliver • a framework that not only provides the complete application stack but also eases the way of working with it.
  • 29. Resources ● Main Site                                                   ● Start up Tutorial                                                  ails.html/ ● Devarticles Tutorials                             ­on­ Rails/1/author/