Rail3 intro 29th_sep_surendran
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Rail3 intro 29th_sep_surendran

on

  • 1,137 views

 

Statistics

Views

Total Views
1,137
Views on SlideShare
1,094
Embed Views
43

Actions

Likes
0
Downloads
14
Comments
0

1 Embed 43

http://www.spritle.com 43

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

Rail3 intro 29th_sep_surendran Presentation Transcript

  • 1. Rails3 – Introduction-I - Surendran S http://www.Spritle.com Copyright: Spritle Software Private Limited Please note that some of the images or content might have been taken from Internet and we don’t own copyright on them. If you have any objection in the content, please let us know at info@spritle.com
  • 2. About Me http://www.Spritle.com Copyright: Spritle Software Private Limited
  • 3.  
  • 4.
      • Rails is a web application development framework written in the Ruby language.
      • DRY – “Don’t Repeat Yourself”
      • REST is the best pattern for web applications
    Rails Introduction 
  • 5.
      • Rails is the Model, View, Controller architecture, usually just called MVC.
    Rails Architecture 
  • 6.
      • A model represents the information (data) of the application and the rules to manipulate that data. 
      • In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table.
      •   In most cases, one table in your database will correspond to one model in your application. 
      • The bulk of your application’s business logic will be concentrated in the models  
    MODEL
  • 7.
      • Views represent the user interface of your application.
      • In Rails, views are often HTML files with embedded Ruby code that perform tasks related solely to the presentation of the data. 
      • Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.
    VIEW
  • 8.
      • Controllers provide the “glue” between models and views.
      • In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.
    CONTROLLER
  • 9.
      • Rest stands for Representational State Transfer and is the foundation of the RESTful architecture.
      •   For example, to a Rails application a request such as this:DELETE /photos/17
    REST
  • 10.   $rails new sample Creates a new rails project   CREATING NEW RAILS APP
  • 11.  
  • 12.
    •   $rails new sample
    • Creates a new rails project
    • Configuring a Database
    • The database to use is specified in a configuration file, config/database.yml
    • he file contains sections for three different environments in which Rails can run by default:
      • The development environment is used on your development computer as you interact manually with the application
      • The test environment is used to run automated tests
      • The production environment is used when you deploy your application for the world to use.
    •  
    • The database to use is specified in a configuration file, config/database.yml
    • The file contains sections for three different environments in which Rails can run by default:
      • The development environment is used on your development computer as you interact manually with the application
      • The test environment is used to run automated tests
      • The production environment is used when you deploy your application for the world to use.
    •  
    CONFIGURING DATABASE
  • 13. $ rake db:create $ rails server This will fire up an instance of the Mongrel web server by default  To see your application in action, open a browser window and navigate to http://localhost:3000 . You should see Rails’ default information page: STARING SERVER
  • 14.
      • Brand new router 
      • New Active Record chainable query language built on top of relational algebra
      • Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)
      • Action controller respond_with
      • Explicit dependency management with Bundler 
    Whats new in rails3   
  • 15.            Old                                             New script/generate                              rails g script/console                                rails c script/server                                  rails s script/dbconsole                            rails db
  • 16. $ rails generate scaffold Post name:string title:string content:text
  • 17.      Old                                                     New script/generate                              rails g script/console                                rails c script/server                                  rails s script/dbconsole                             rails db rake db:migrate creates a table and add the 3 columns in the table  MODEL AND MIGRATION
  • 18. $ rails generate model Comment commenter:string body:text post:references
  • 19. Rails 2 config/routes.rb TestApp::Application.routes.draw do |map| map.resources :posts end Rails 3 TestApp::Application.routes.draw do resources :posts end ROUTES
  • 20. creates seven different routes in your application, all mapping to the Posts controller ROUTES
  • 21. Rails 2 resources :posts do |post| post.resources :comments end Rails 3 resources :posts do resources :comments end This creates comments as a  nested resource  within posts. This is another part of capturing the hierarchical relationship that exists between posts and comments ROUTES
  • 22. Rails 2 @posts = Post.find(:all, :conditions => {:published => true}) immediately queries the db returns an Array of Posts Rails 3@posts = Post.where(:published => true) doesn’t query the db returns an ActiveRecord::Relation ActiveRelation
  • 23.      Old                                                     New script/generate                              rails g script/console                                rails c script/server                                  rails s script/dbconsole                             rails db @posts.each do |p| ... end ActiveRelation Query runs here this is Lazy loading
  • 24. @published = Post.published will return  you the posts whose ppublished column is true Class Post < ActiveRecord::Base default_scope order('title') scope :published, where(:published => true) scope :unpublished, where(:published => false) end ActiveRelation
  • 25. Rails 2 Post.find(:all, :conditions => {:author => &quot;Joe&quot;}, :includes => :comments,:order => &quot;title&quot;, :limit => 10) Rails 3 Post.where(:author=>Joe&quot;).include(:comments).order(:title).limit(10) ActiveRelation
  • 26. BUNDLER $bundle install  Will ensure all gems are installed, including webrat (but it’s only included in test mode). $bundle --without test Will install everything except webrat. gemfile
  • 27. HTML 5 custom data attributes data-* Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements data-remote data-method data-confirm data-disable-with Adopting Unobtrusive Javascript
  • 28. Rails 2 <%= link_to_remote 'Show', :url => post %> <a href=&quot;#&quot; onclick=&quot;new Ajax.Request('/posts/1', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('9sk..44d')}); return false;&quot;>Show</a> Rails 3 <%= link_to 'Show', post, :remote => true %> <a href=&quot;/posts/1&quot; data-remote=&quot;true&quot;>Show</a> Adopting Unobtrusive Javascript
  • 29.   Adopting Unobtrusive Javascript
  • 30.   Adopting Unobtrusive Javascript document.observe(&quot;dom:loaded&quot;, function() { $(document.body).observe(&quot;click&quot;, function(event) { var message = event.element().readAttribute('data-confirm'); if (message) { // ... Do a confirm box } var element = event.findElement(&quot;a[data-remote=true]&quot;); if (element) { // ... Do the AJAX call } var element = event.findElement(&quot;a[data-method]&quot;); if (element) { // ... Create a form } })
  • 31. http://github.com/rails/jquery-uj $('a[data-confirm],input[data-confirm]').live('click', function () { // ... Do a confirm box }); $('form[data-remote=&quot;true&quot;]').live('submit', function (e) { // ... Do an AJAX call }); jQuery in Rails?
  • 32. Thanks & Questions