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

  • 1,731 views
Uploaded 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 …

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,731
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
10
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Ruby on Rails Technology
  • 2. MVC
  • 3. ModelController View
  • 4. MVC ● Controller Model ● View
  • 5. MVC
  • 6. RESTful routing REST Representational state transfer
  • 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. RESTful routingConfigurationresources :posts
  • 9. Modelclass Post < ActiveRecord::Base validates :title, :presence => trueend
  • 10. Controllerclass PostController < ApplicationController def index @posts = Post.all logger.info Post loaded endend
  • 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. Technology● Unobtrusive Javascript● Built in jquery and prototype● Coffeescript● HTML 5● Haml / Sass● Internationalization● Data migration● Dependency management
  • 13. PerformanceImprove performance● Caching● Asset pipelineTest performance
  • 14. Improve performanceCaching- Page caching- Action caching- Fragment Caching● Reference● http://guides.rubyonrails.org/caching_with_rails.html
  • 15. Configurationconfig.action_controller.perform_caching = true
  • 16. Page cachingclass ProductsController < ActionController caches_page :index def index @products = Products.all end def create expire_page :action => :index endend
  • 17. Page cachingAppropriate for Not for● Public pages ● Pages that require● Pages that do not authentication change often ● Pages that changes often
  • 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. 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. Caching Use Sweepers to expire cache
  • 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. Sweepers to expire cachingclass ProductsController < ActionController before_filter :authenticate caches_action :index cache_sweeper :product_sweeper def index @products = Product.all endend
  • 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. 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. Improve performance Asset pipeline ???● Reference● http://guides.rubyonrails.org/asset_pipeline.html
  • 26. Asset pipelining
  • 27. Asset pipelining Assets
  • 28. Asset pipelining Compile Compiled asset Assets
  • 29. Asset pipeliningUsageapp/assets/javascripts/application.jsapp/assets/javascripts/home.jsapp/assets/javascripts/menu.jsapp/assets/javascripts/slider.js Compiled asset Assets
  • 30. Asset pipeliningUsageIn application.js add the following, //= require home //= require moovinator Compiled asset //= require slider Assets
  • 31. Asset pipeliningUsageAdd application.js in you template as follows, <%= javascript_include_tag "application" %> Compiled asset Assets
  • 32. Deployment● Using capistrano magic●● cap deploy● Reference Compiled asset● https://github.com/capistrano/capistrano/wiki Assets
  • 33. Learn Rails● Guides● http://guides.rubyonrails.org●● Video casts● http://railscasts.com● http://rubyonrails.org/screencasts asset Compiled Assets
  • 34. A.K.M. Ashrafuzzaman Sr. Technology Analyst, Orbundwww.ashrafuzzaman.comjitu-blog.blogspot.comwww.orbund.com
  • 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