Upload
akm-ashrafuzzaman
View
1.790
Download
1
Embed Size (px)
DESCRIPTION
In July 2004 David Heinemeier Hansson aka dhh, a Danish programmer came up with a web application framework while building a project management tool named Basecamp. In 2012 it is now one of the fastest growing web frameworks in world. Tens of Thousands Rails applications like Basecamp, Twitter, Github, Groupon, and our own (in Bangladesh) akhoni.com and bdipo.com are live. Ruby on Rails (RoR) claims to be a breakthrough in lowering the barriers of entry to programming. Powerful web applications that formerly took months to develop can be produced now in a days. RoR is now official platform for many startup incubators. In this session we will introduce and explore the zeal of RoR. We will see how this can optimize programmer's happiness and sustainable productivity. This was presented in Basis Softexpo 2012 and arranged by Nascenia IT, the leading Ruby on Rails development company in Bangladesh.
Citation preview
Ruby on RailsTechnology
MVC
ModelController
View
MVC
●
ControllerModel
●View
MVC
RESTful routing
RESTRepresentational state transfer
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
RESTful routing
resources :posts
Configuration
Model
class Post < ActiveRecord::Base validates :title, :presence => trueend
Controller
class PostController < ApplicationController
def index @posts = Post.all logger.info 'Post loaded' end
end
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>
Technology● Unobtrusive Javascript● Built in jquery and prototype● Coffeescript● HTML 5● Haml / Sass● Internationalization● Data migration● Dependency management
PerformanceImprove performance● Caching● Asset pipeline
Test performance
Improve performanceCaching
- Page caching
- Action caching
- Fragment Caching
● Reference● http://guides.rubyonrails.org/caching_with_rails.html
Configuration
config.action_controller.perform_caching = true
Page caching
class ProductsController < ActionController caches_page :index def index @products = Products.all end def create expire_page :action => :index endend
Page caching
Appropriate for● Public pages● Pages that do not
change often
Not for● Pages that require
authentication● Pages that changes
often
Action caching
class ProductsController < ActionController before_filter :authenticate caches_action :index def index @products = Product.all end def create expire_action :action => :index endend
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
Caching
Use Sweepers to expire cache
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
Sweepers to expire caching
class ProductsController < ActionController before_filter :authenticate caches_action :index cache_sweeper :product_sweeper def index @products = Product.all end end
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"
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
Improve performance
Asset pipeline ???
● Reference● http://guides.rubyonrails.org/asset_pipeline.html
Asset pipelining
Asset pipelining
Assets
Asset pipelining
Com
p ile
Assets
Compiled asset
Asset pipelining
Assets
Compiled asset
Usage
app/assets/javascripts/application.jsapp/assets/javascripts/home.jsapp/assets/javascripts/menu.jsapp/assets/javascripts/slider.js
Asset pipelining
Assets
Compiled asset
UsageIn application.js add the following,
//= require home//= require moovinator//= require slider
Asset pipelining
Assets
Compiled asset
UsageAdd application.js in you template as follows,
<%= javascript_include_tag "application" %>
Deployment
Assets
Compiled asset● Reference● https://github.com/capistrano/capistrano/wiki
● Using capistrano magic●
● cap deploy
Learn Rails
Assets
Compiled asset
● Guides● http://guides.rubyonrails.org●
● Video casts● http://railscasts.com● http://rubyonrails.org/screencasts
A.K.M. Ashrafuzzaman Sr. Technology Analyst,
Orbund
www.ashrafuzzaman.comjitu-blog.blogspot.comwww.orbund.com
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