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
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
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
30. Adopting Unobtrusive Javascript document.observe("dom:loaded", function() { $(document.body).observe("click", function(event) { var message = event.element().readAttribute('data-confirm'); if (message) { // ... Do a confirm box } var element = event.findElement("a[data-remote=true]"); if (element) { // ... Do the AJAX call } var element = event.findElement("a[data-method]"); if (element) { // ... Create a form } })