SlideShare ist ein Scribd-Unternehmen logo
1 von 32
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
About Me http://www.Spritle.com Copyright: Spritle Software Private Limited
 
[object Object],[object Object],[object Object],Rails Introduction 
[object Object],Rails Architecture 
[object Object],[object Object],[object Object],[object Object],MODEL
[object Object],[object Object],[object Object],VIEW
[object Object],[object Object],CONTROLLER
[object Object],[object Object],REST
  $rails new sample Creates a new rails project   CREATING NEW RAILS APP
 
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CONFIGURING DATABASE
$ 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
[object Object],[object Object],[object Object],[object Object],[object Object],Whats new in rails3   
           Old                                             New script/generate                              rails g script/console                                rails c script/server                                  rails s script/dbconsole                            rails db
$ rails generate scaffold Post name:string title:string content:text
     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
$ rails generate model Comment commenter:string body:text post:references
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
creates seven different routes in your application, all mapping to the Posts controller ROUTES
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
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
     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
@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
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
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
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
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
  Adopting Unobtrusive Javascript
  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 } })
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?
Thanks  &  Questions

Weitere ähnliche Inhalte

Was ist angesagt?

Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertKaty Slemon
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialKaty Slemon
 
Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621Banking at Ho Chi Minh city
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajaxs_pradeep
 
Introduction to Rails
Introduction to RailsIntroduction to Rails
Introduction to RailsBlazing Cloud
 
4 introduction-php-mvc-cakephp-m4-controllers-slides
4 introduction-php-mvc-cakephp-m4-controllers-slides4 introduction-php-mvc-cakephp-m4-controllers-slides
4 introduction-php-mvc-cakephp-m4-controllers-slidesMasterCode.vn
 
How to set up and test a Rails 3 Engine
How to set up and test a Rails 3 EngineHow to set up and test a Rails 3 Engine
How to set up and test a Rails 3 Enginenicholasf
 
A linux mac os x command line interface
A linux mac os x command line interfaceA linux mac os x command line interface
A linux mac os x command line interfaceDavid Walker
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...
Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...
Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...Roel Hartman
 
Edition Based Redefinition
Edition Based RedefinitionEdition Based Redefinition
Edition Based RedefinitionAlex Nuijten
 

Was ist angesagt? (20)

Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorial
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
Derailing rails
Derailing railsDerailing rails
Derailing rails
 
Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621Ibm tivoli access manager for e business junctions and links redp4621
Ibm tivoli access manager for e business junctions and links redp4621
 
Rails Page Caching
Rails Page CachingRails Page Caching
Rails Page Caching
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Introduction to Rails
Introduction to RailsIntroduction to Rails
Introduction to Rails
 
4 introduction-php-mvc-cakephp-m4-controllers-slides
4 introduction-php-mvc-cakephp-m4-controllers-slides4 introduction-php-mvc-cakephp-m4-controllers-slides
4 introduction-php-mvc-cakephp-m4-controllers-slides
 
How to set up and test a Rails 3 Engine
How to set up and test a Rails 3 EngineHow to set up and test a Rails 3 Engine
How to set up and test a Rails 3 Engine
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
A linux mac os x command line interface
A linux mac os x command line interfaceA linux mac os x command line interface
A linux mac os x command line interface
 
Routing
RoutingRouting
Routing
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Web api
Web apiWeb api
Web api
 
Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...
Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...
Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefiniti...
 
Edition Based Redefinition
Edition Based RedefinitionEdition Based Redefinition
Edition Based Redefinition
 
Rack
RackRack
Rack
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 

Ähnlich wie Rail3 intro 29th_sep_surendran

Rails
RailsRails
RailsSHC
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction Tran Hung
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails SiddheshSiddhesh Bhobe
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon RailsPaul Pajo
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...Matt Gauger
 
Ruby Rails Web Development
Ruby Rails Web DevelopmentRuby Rails Web Development
Ruby Rails Web DevelopmentSonia Simi
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on RailsDelphiCon
 

Ähnlich wie Rail3 intro 29th_sep_surendran (20)

Rails
RailsRails
Rails
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon Rails
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby on Rails
Ruby on Rails Ruby on Rails
Ruby on Rails
 
Ruby on rails RAD
Ruby on rails RADRuby on rails RAD
Ruby on rails RAD
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 
Ruby Rails Web Development
Ruby Rails Web DevelopmentRuby Rails Web Development
Ruby Rails Web Development
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 

Mehr von SPRITLE SOFTWARE PRIVATE LIMIT ED (9)

Draper - Visnupriya - spriteXchange
Draper - Visnupriya - spriteXchangeDraper - Visnupriya - spriteXchange
Draper - Visnupriya - spriteXchange
 
Introduction to Node.js by Vinothini B
Introduction to Node.js by Vinothini BIntroduction to Node.js by Vinothini B
Introduction to Node.js by Vinothini B
 
Intro to Amplifyjs by Visnupriya
Intro to Amplifyjs by VisnupriyaIntro to Amplifyjs by Visnupriya
Intro to Amplifyjs by Visnupriya
 
Intro to Raspberry Pi - by Sivakumar V
Intro to Raspberry Pi - by Sivakumar VIntro to Raspberry Pi - by Sivakumar V
Intro to Raspberry Pi - by Sivakumar V
 
Arduino for developers by Steve Robinson
Arduino for developers by Steve RobinsonArduino for developers by Steve Robinson
Arduino for developers by Steve Robinson
 
Cross platform mobile apps using rhomobile and jquery mobile
Cross platform mobile apps using rhomobile and jquery mobileCross platform mobile apps using rhomobile and jquery mobile
Cross platform mobile apps using rhomobile and jquery mobile
 
Introduction to Rhodes - By Surendran - Spritle software
Introduction to Rhodes - By Surendran - Spritle softwareIntroduction to Rhodes - By Surendran - Spritle software
Introduction to Rhodes - By Surendran - Spritle software
 
HTML5 Introduction by Dhepthi L
HTML5 Introduction by Dhepthi LHTML5 Introduction by Dhepthi L
HTML5 Introduction by Dhepthi L
 
J query intro_29thsep_alok
J query intro_29thsep_alokJ query intro_29thsep_alok
J query intro_29thsep_alok
 

Rail3 intro 29th_sep_surendran

  • 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.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.   $rails new sample Creates a new rails project   CREATING NEW RAILS APP
  • 11.  
  • 12.
  • 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.
  • 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
  • 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