Ruby and Ruby­on­Rails
Upcoming SlideShare
Loading in...5
×
 

Ruby and Ruby­on­Rails

on

  • 848 views

 

Statistics

Views

Total Views
848
Views on SlideShare
848
Embed Views
0

Actions

Likes
0
Downloads
12
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ruby and Ruby­on­Rails Ruby and Ruby­on­Rails Presentation Transcript

  • Ruby and Ruby­on­Rails 17th of November, 2007 Hyderabad, India
  • We appreciate 
  • Outline ● Ruby ● Ruby­on­Rails − Ruby­on­Rails: What is it? − MVC Pattern − Scaffolding − Active Record − Action View − Action Controller − Rails and Ajax View slide
  • Outline − Action Mailer − Web Service − IDE support ● Conclusion View slide
  • 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
  • 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
  • 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
  • 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)
  • Ruby Tools The following tools are included with the Ruby distribution − debugger − irb – interactive ruby shell − benchmark − profiler − rdoc
  • Ruby­on­Rails
  • 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
  • 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.
  • 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.
  • Model­View­Controller (MVC) 1 User Web browser 2 7 Views View Controller 5, 6 3, 4 Models Model end
  • 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
  • Rails Models ActiveRecord Model Classes − Encapsulate persistence logic − Contain business rules − Tightly coupled to database tables − Declare relationships to each other
  • 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)
  • 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
  • ERB Template Example
  • 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
  • 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
  • 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.
  • 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.
  • 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.
  • 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
  • Web Services  RESTful Services − Uses HTTP itself as transport mechanism − respond_to helps to convert simple action methods to  RESTful action methods
  • IDEs for Rails ● Eclipse − RadRails ● Netbeans − Netbeans 6 has in built support using JRuby ● CodeGear
  • 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.
  • Resources ● Main Site                                                            http://www.rubyonrails.org// ● Start up Tutorial                                                           http://www.onlamp.com/pub/a/onlamp/2005/01/20/r ails.html/ ● Devarticles Tutorials                                       http://www.devarticles.com/c/b/Ruby­on­ Rails/1/author/