Ride on the Fast Track of Web with Ruby on Rails- Part 2


Published on

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.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ride on the Fast Track of Web with Ruby on Rails- Part 2

  1. 1. Ruby on Rails Technology
  2. 2. MVC
  3. 3. ModelController View
  4. 4. MVC ● Controller Model ● View
  5. 5. MVC
  6. 6. RESTful routing REST Representational state transfer
  7. 7. RESTful routingHTTP Verb Path ActionGET /posts indexGET /posts/new newPOST /posts createGET /posts/:id showGET /posts/:id/edit editPUT /posts/:id updateDELETE /posts/:id destroy
  8. 8. RESTful routingConfigurationresources :posts
  9. 9. Modelclass Post < ActiveRecord::Base validates :title, :presence => trueend
  10. 10. Controllerclass PostController < ApplicationController def index @posts = Post.all logger.info Post loaded endend
  11. 11. 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>
  12. 12. Technology● Unobtrusive Javascript● Built in jquery and prototype● Coffeescript● HTML 5● Haml / Sass● Internationalization● Data migration● Dependency management
  13. 13. PerformanceImprove performance● Caching● Asset pipelineTest performance
  14. 14. Improve performanceCaching- Page caching- Action caching- Fragment Caching● Reference● http://guides.rubyonrails.org/caching_with_rails.html
  15. 15. Configurationconfig.action_controller.perform_caching = true
  16. 16. Page cachingclass ProductsController < ActionController caches_page :index def index @products = Products.all end def create expire_page :action => :index endend
  17. 17. Page cachingAppropriate for Not for● Public pages ● Pages that require● Pages that do not authentication change often ● Pages that changes often
  18. 18. Action cachingclass ProductsController < ActionController before_filter :authenticate caches_action :index def index @products = Product.all end def create expire_action :action => :index endend
  19. 19. Fragment cachingIn template<% cache(all_available_products) do %> All available products: <% Product.all.each do |p| %> <%= link_to p.name, product_url(p) %> <% end %><% end %>Expire cachexpire_fragment(all_available_products)
  20. 20. Caching Use Sweepers to expire cache
  21. 21. Sweepers to expire cachingclass 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
  22. 22. Sweepers to expire cachingclass ProductsController < ActionController before_filter :authenticate caches_action :index cache_sweeper :product_sweeper def index @products = Product.all endend
  23. 23. Configure cachingActionController::Base.cache_store = :memory_store orActionController::Base.cache_store = :file_store, "/path/to/cache/directory" orActionController::Base.cache_store = :mem_cache_store, "cache-1.example.com"
  24. 24. Test performance● Benchmarking web site performance● class HomepageTest < ActionDispatch::PerformanceTest # Replace this with your real tests. def test_homepage get / end end http://guides.rubyonrails.org/performance_testing.html
  25. 25. Improve performance Asset pipeline ???● Reference● http://guides.rubyonrails.org/asset_pipeline.html
  26. 26. Asset pipelining
  27. 27. Asset pipelining Assets
  28. 28. Asset pipelining Compile Compiled asset Assets
  29. 29. Asset pipeliningUsageapp/assets/javascripts/application.jsapp/assets/javascripts/home.jsapp/assets/javascripts/menu.jsapp/assets/javascripts/slider.js Compiled asset Assets
  30. 30. Asset pipeliningUsageIn application.js add the following, //= require home //= require moovinator Compiled asset //= require slider Assets
  31. 31. Asset pipeliningUsageAdd application.js in you template as follows, <%= javascript_include_tag "application" %> Compiled asset Assets
  32. 32. Deployment● Using capistrano magic●● cap deploy● Reference Compiled asset● https://github.com/capistrano/capistrano/wiki Assets
  33. 33. Learn Rails● Guides● http://guides.rubyonrails.org●● Video casts● http://railscasts.com● http://rubyonrails.org/screencasts asset Compiled Assets
  34. 34. A.K.M. Ashrafuzzaman Sr. Technology Analyst, Orbundwww.ashrafuzzaman.comjitu-blog.blogspot.comwww.orbund.com
  35. 35. Presented Athttp://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