![Page 1: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/1.jpg)
Ruby on RailsTechnology
![Page 2: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/2.jpg)
MVC
![Page 3: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/3.jpg)
ModelController
View
![Page 4: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/4.jpg)
MVC
●
ControllerModel
●View
![Page 5: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/5.jpg)
MVC
![Page 6: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/6.jpg)
RESTful routing
RESTRepresentational state transfer
![Page 7: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/7.jpg)
RESTful routingHTTP Verb Path Action
GET /posts index
GET /posts/new new
POST /posts create
GET /posts/:id show
GET /posts/:id/edit edit
PUT /posts/:id update
DELETE /posts/:id destroy
![Page 8: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/8.jpg)
RESTful routing
resources :posts
Configuration
![Page 9: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/9.jpg)
Model
class Post < ActiveRecord::Base validates :title, :presence => trueend
![Page 10: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/10.jpg)
Controller
class PostController < ApplicationController
def index @posts = Post.all logger.info 'Post loaded' end
end
![Page 11: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/11.jpg)
View<h1>Listing posts</h1> <table> <tr> <th>Name</th> <th>Title</th> <th>Content</th> </tr> <% @posts.each do |post| %> <tr> <td><%= post.name %></td> <td><%= post.title %></td> <td><%= post.content %></td> </tr><% end %></table>
![Page 12: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/12.jpg)
Technology● Unobtrusive Javascript● Built in jquery and prototype● Coffeescript● HTML 5● Haml / Sass● Internationalization● Data migration● Dependency management
![Page 13: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/13.jpg)
PerformanceImprove performance● Caching● Asset pipeline
Test performance
![Page 14: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/14.jpg)
Improve performanceCaching
- Page caching
- Action caching
- Fragment Caching
● Reference● http://guides.rubyonrails.org/caching_with_rails.html
![Page 15: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/15.jpg)
Configuration
config.action_controller.perform_caching = true
![Page 16: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/16.jpg)
Page caching
class ProductsController < ActionController caches_page :index def index @products = Products.all end def create expire_page :action => :index endend
![Page 17: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/17.jpg)
Page caching
Appropriate for● Public pages● Pages that do not
change often
Not for● Pages that require
authentication● Pages that changes
often
![Page 18: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/18.jpg)
Action caching
class ProductsController < ActionController before_filter :authenticate caches_action :index def index @products = Product.all end def create expire_action :action => :index endend
![Page 19: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/19.jpg)
Fragment caching
<% cache('all_available_products') do %> All available products: <% Product.all.each do |p| %> <%= link_to p.name, product_url(p) %> <% end %><% end %>
expire_fragment('all_available_products')
Expire cach
In template
![Page 20: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/20.jpg)
Caching
Use Sweepers to expire cache
![Page 21: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/21.jpg)
Sweepers to expire caching
class ProductSweeper < ActionController::Caching::Sweeper observe Product # This sweeper is going to keep an eye on the Product model
def after_create(product) expire_cache_for(product) end def after_update(product) expire_cache_for(product) end def after_destroy(product) expire_cache_for(product) end private def expire_cache_for(product) expire_page(:controller => 'products', :action => 'index') expire_fragment('all_available_products') endend
![Page 22: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/22.jpg)
Sweepers to expire caching
class ProductsController < ActionController before_filter :authenticate caches_action :index cache_sweeper :product_sweeper def index @products = Product.all end end
![Page 23: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/23.jpg)
Configure caching
ActionController::Base.cache_store = :memory_storeor
ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"or
ActionController::Base.cache_store = :mem_cache_store, "cache-1.example.com"
![Page 24: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/24.jpg)
Test performance● Benchmarking web site performance●
http://guides.rubyonrails.org/performance_testing.html
class HomepageTest < ActionDispatch::PerformanceTest # Replace this with your real tests. def test_homepage get '/' endend
![Page 25: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/25.jpg)
Improve performance
Asset pipeline ???
● Reference● http://guides.rubyonrails.org/asset_pipeline.html
![Page 26: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/26.jpg)
Asset pipelining
![Page 27: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/27.jpg)
Asset pipelining
Assets
![Page 28: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/28.jpg)
Asset pipelining
Com
p ile
Assets
Compiled asset
![Page 29: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/29.jpg)
Asset pipelining
Assets
Compiled asset
Usage
app/assets/javascripts/application.jsapp/assets/javascripts/home.jsapp/assets/javascripts/menu.jsapp/assets/javascripts/slider.js
![Page 30: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/30.jpg)
Asset pipelining
Assets
Compiled asset
UsageIn application.js add the following,
//= require home//= require moovinator//= require slider
![Page 31: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/31.jpg)
Asset pipelining
Assets
Compiled asset
UsageAdd application.js in you template as follows,
<%= javascript_include_tag "application" %>
![Page 32: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/32.jpg)
Deployment
Assets
Compiled asset● Reference● https://github.com/capistrano/capistrano/wiki
● Using capistrano magic●
● cap deploy
![Page 33: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/33.jpg)
Learn Rails
Assets
Compiled asset
● Guides● http://guides.rubyonrails.org●
● Video casts● http://railscasts.com● http://rubyonrails.org/screencasts
![Page 34: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/34.jpg)
A.K.M. Ashrafuzzaman Sr. Technology Analyst,
Orbund
www.ashrafuzzaman.comjitu-blog.blogspot.comwww.orbund.com
![Page 35: Ride on the Fast Track of Web with Ruby on Rails- Part 2](https://reader033.vdocuments.us/reader033/viewer/2022042700/554a3a90b4c90582328b4b0a/html5/thumbnails/35.jpg)
http://www.softexpo.com.bd/technical_details.php?id=9To see 1st part of this presentation visit:http://www.slideshare.net/fuadcse/ride-on-the-fast-track-of-web-with-ruby-on-rails-part-1
Presented At