SlideShare a Scribd company logo
Fitting for the occasion


      MeetUP @ Balabit



         October 14, 2010
         nucc@balabit.com
Rails 3.0

• Merb + Rails 2.3 = Rails 3.0
• Bundler
• Rack
• HTML 5
• Arel
Rails 3.0

 • Merb + Rails 2.3 = Rails 3.0
users                                 
  .where(users[:name].eq('nucc'))       
 • Bundler
  .project(users[:id])                
# => SELECT users.id FROM users WHERE users.name = 'nucc'
 • Rack
users.where(users[:name].eq('bob')).where(users[:age].lt(25))
#•=> SELECT * FROM users where users.name=’bob’ and users.age < 25
   HTML 5
 • Arel
users.where(users[:name].eq('bob').or(users[:age].lt(25)))
# => SELECT * FROM users where users.name=’bob’ or users.age < 25

valid_users = users.where(users[:valid].eq(1))
men = valid_users.where(users[:sex].eq(1))
women = valid_users.where(users[:sex].eq(2))
number_of_women = women.count()
Sharing information

  Product   Products
  Model     Controller
Sharing information

  Product   Products
  Model     Controller
REST

• Representational State Transfer

• Roy Fielding - 2000
• SOAP is a protocol, REST is an architecture
• Representation of a resource
• iWiW, Facebook, GitHub, Twitter, Google Search
REST Mapping

    Verb          Path           Action
    GET        /products         index
    GET       /products/:id      show
    POST       /products         create
    GET     /products/:id/edit    edit
    PUT       /products/:id      update
   DELETE     /products/:id      delete
Configuration
 /app/models/product.rb                     /app/controllers/products_controller.rb
 class Product < ActiveRecord::Base         class Products < ApplicationController
 end
                                             def index
                                              @products = Product.all
                                             end

                                             def show
                                              @product = Product.find params[:id]
                                             end


 config/routes.rb                             def update
                                                ...
 Meetup::Application.routes.draw do |map|
                                             end
  resources :products
                                             ...
 end
                                            end
Using resource
/app/models/user.rb
class User < ActiveResource::Base
   site.url = “http://api.twitter.com”
end

                                         /app/controller/user_controller.rb
                                         class UserController < ActionController::Base
                                            self.site = “http://api.twitter.com”

                                           self.element_name = “user”
                                           self.proxy = “...”
                                           self.timeout = 5
                                           self.ssl_options = { :key => “...” }
                                         end
Fitting for the occasion

  Product   Product
  Model     Controller
Fitting for the occasion

                            HTTP
  Product   Product
  Model     Controller
                                Android UI / XML

                                   iPhone UI / XML


                                XML

                         JSON
Respond to
class ProductsController < Application
  def index
   @products = Product.all

  respond_to do |format|
    format.html                 # index.html.erb
    format.iphone               # index.iphone.erb
    format.json { render :json => @products }
    format.xml { render :xml => @products}
  end
 end
end
Fitting for the occasion

            Product    /products.html
  Product
  Model     Controller
                                 /products.xml

                                  /products.iphone


                           /products.rss

                  /products.js
Review


         /app/models
         /app/controllers


         /app/views
         /app/helpers
Rendering
render :xml => @products
render :json => @products
render :file => “../owners/owner.html.erb”
render :text => “Hello World”


render :update do |page|
 page.replace_html(“products”, :partial => product, :object=> @product)
end
Views
                                Layout
                :header

                     content




                                         index.html.erb
        :menu      product #1

                   product #2

                   product #3


                :footer
Layout
 # layout.html.erb           # index.html.erb
 <html>
  <body>                     <%= content_for :header do %>
   <div class=”header”>        <span> BALABIT Products </span>
     <%= yield :header %>    <% end %>
   </div>
   <div class=”content”>     <%= content_for :menu do %>
     <div class=”menu”>        <li>Special menu item</li>
        <%= yield :menu %>   <% end %>
     </div>
   </div>
                             <div class=”products”>
   <div class=”content”>       ...
    <%= yield %>             </div>
   </div>

    ...
Partial

/app/views/products/index.html.erb
            content              #object
                                 render :partial => “product”, :object => ...
          product #1
                                 #array
                                 render :partial => “product”, :collection => ...
          product #2

          product #3


                         /app/views/products/_product.html.erb
Partial
                             # /app/views/products/index.html.erb
                             <div class=”products”>
                              <%= render :partial => “product”, :collection => @products %>
/app/views/products/index.html.erb
                             </div>

            content          # /app/views/products/_product.html.erb
                                   #object
                             <div class=”product”>
                               <span class=”title”><%= product.name %></span> =>
                                    render :partial => “product”, :object             ...
          product #1           <span class=”owner”><%= product.owner %></span>
                             </div>#array
                                  render :partial => “product”, :collection => ...
          product #2         # result
                             <div class=”products”>
                              <div class=”product”>
          product #3             <span class=”title”>SCB</span>
                                 <span class=”owner”>Marci</span>
                              </div>
                             </div>
                         /app/views/products/_product.html.erb
Helpers

/app/views/products/index.html.erb                  /app/helpers/products_helper.rb
<div>                                               module ProductsHelper
  <span> Number of products: </span>
  <%= number_of_products(@product) %>                def number_of_products( products )
<div>                                                 products.select{ |p| p.active? }.size
                                                     end
<% form_for @product, :remote => true do | f | %>
 <%= f.text_field :version %>                        end
<% end %>
Cache
class ProductController < Application   class ProductController < Application
                                           before_filter :authentication
  caches_page :index                       caches_action :index

  def index                               def index
   @products = Product.all                 @products = Product.all
  end                                     end

    def create                              def create
      expire_page :action => :index           expire_page :action => :index
      ...                                     ...
    end                                     end
 ...                                     ...
end                                     end
Cache
<html>
 <body>

<% cache do %>
  <div class=”menu”>
   <li>Show products</li>
  </div>
<% end %>

<% cache(:action => 'update', :action_suffix => 'products') do %>
  <div class=”products”>
    <%= render :partial => “product”, :collection => @products %>
  </div>
<% end %>

# expire_fragment( :controller => ‘products’, :action => 'index', :action_suffix => 'products')
Questions?
Thank you!

More Related Content

What's hot

Single Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and RailsSingle Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and Rails
Prateek Dayal
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
Dzmitry Ivashutsin
 
Solid angular
Solid angularSolid angular
Solid angular
Nir Kaufman
 
Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
Ivan Chepurnyi
 
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiFixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Meet Magento Spain
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging
varien
 
Applications: A Series of States
Applications: A Series of StatesApplications: A Series of States
Applications: A Series of States
Trek Glowacki
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Nicolás Bouhid
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwan
Tse-Ching Ho
 
Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)
Jake Goldman
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
Nir Kaufman
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30fiyuer
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
Cape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community ToolkitCape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community Toolkit
Javier Suárez Ruiz
 
MVVM with SwiftUI and Combine
MVVM with SwiftUI and CombineMVVM with SwiftUI and Combine
MVVM with SwiftUI and Combine
Tai Lun Tseng
 
ChocolateChip-UI
ChocolateChip-UIChocolateChip-UI
ChocolateChip-UI
GeorgeIshak
 
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptWhy SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptmartinlippert
 
Angular JS Routing
Angular JS RoutingAngular JS Routing
Angular JS Routing
kennystoltz
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
KyeongMook "Kay" Cha
 

What's hot (20)

Single Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and RailsSingle Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and Rails
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Solid angular
Solid angularSolid angular
Solid angular
 
Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
 
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiFixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan Chepurnyi
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging
 
Applications: A Series of States
Applications: A Series of StatesApplications: A Series of States
Applications: A Series of States
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwan
 
Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Cape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community ToolkitCape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community Toolkit
 
MVVM with SwiftUI and Combine
MVVM with SwiftUI and CombineMVVM with SwiftUI and Combine
MVVM with SwiftUI and Combine
 
ChocolateChip-UI
ChocolateChip-UIChocolateChip-UI
ChocolateChip-UI
 
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptWhy SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
 
Angular JS Routing
Angular JS RoutingAngular JS Routing
Angular JS Routing
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 

Viewers also liked

Open Academy - Ruby
Open Academy - RubyOpen Academy - Ruby
Open Academy - RubyPapp Laszlo
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Papp Laszlo
 
Shade műhely
Shade műhelyShade műhely
Shade műhely
Papp Laszlo
 
Ruby gems
Ruby gemsRuby gems
Ruby gems
Papp Laszlo
 
Munkafolyamatok modellezése OPM segítségével
Munkafolyamatok modellezése OPM segítségévelMunkafolyamatok modellezése OPM segítségével
Munkafolyamatok modellezése OPM segítségével
Papp Laszlo
 

Viewers also liked (8)

Rails Models
Rails ModelsRails Models
Rails Models
 
Have2do.it
Have2do.itHave2do.it
Have2do.it
 
Open Academy - Ruby
Open Academy - RubyOpen Academy - Ruby
Open Academy - Ruby
 
Git thinking
Git thinkingGit thinking
Git thinking
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Shade műhely
Shade műhelyShade műhely
Shade műhely
 
Ruby gems
Ruby gemsRuby gems
Ruby gems
 
Munkafolyamatok modellezése OPM segítségével
Munkafolyamatok modellezése OPM segítségévelMunkafolyamatok modellezése OPM segítségével
Munkafolyamatok modellezése OPM segítségével
 

Similar to Resource and view

Simple restfull app_s
Simple restfull app_sSimple restfull app_s
Simple restfull app_snetwix
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2
A.K.M. Ahsrafuzzaman
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxWen-Tien Chang
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
Microsoft
 
WebcampZG - Rails 4
WebcampZG - Rails 4WebcampZG - Rails 4
WebcampZG - Rails 4shnikola
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
Mark
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
Alex Benoit
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
实战Ecos
实战Ecos实战Ecos
实战Ecos
wanglei999
 
Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
Kadiv Vech
 
Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel
Engine Yard
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
Chul Ju Hong
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
Chul Ju Hong
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
Plataformatec
 
Presentation.Key
Presentation.KeyPresentation.Key
Presentation.Keyguesta2b31d
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
Fabio Akita
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
Mark
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperfNew Relic
 

Similar to Resource and view (20)

The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Simple restfull app_s
Simple restfull app_sSimple restfull app_s
Simple restfull app_s
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
WebcampZG - Rails 4
WebcampZG - Rails 4WebcampZG - Rails 4
WebcampZG - Rails 4
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
实战Ecos
实战Ecos实战Ecos
实战Ecos
 
Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
 
Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
Presentation.Key
Presentation.KeyPresentation.Key
Presentation.Key
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Resource and view

  • 1. Fitting for the occasion MeetUP @ Balabit October 14, 2010 nucc@balabit.com
  • 2. Rails 3.0 • Merb + Rails 2.3 = Rails 3.0 • Bundler • Rack • HTML 5 • Arel
  • 3. Rails 3.0 • Merb + Rails 2.3 = Rails 3.0 users .where(users[:name].eq('nucc')) • Bundler .project(users[:id]) # => SELECT users.id FROM users WHERE users.name = 'nucc' • Rack users.where(users[:name].eq('bob')).where(users[:age].lt(25)) #•=> SELECT * FROM users where users.name=’bob’ and users.age < 25 HTML 5 • Arel users.where(users[:name].eq('bob').or(users[:age].lt(25))) # => SELECT * FROM users where users.name=’bob’ or users.age < 25 valid_users = users.where(users[:valid].eq(1)) men = valid_users.where(users[:sex].eq(1)) women = valid_users.where(users[:sex].eq(2)) number_of_women = women.count()
  • 4. Sharing information Product Products Model Controller
  • 5. Sharing information Product Products Model Controller
  • 6. REST • Representational State Transfer • Roy Fielding - 2000 • SOAP is a protocol, REST is an architecture • Representation of a resource • iWiW, Facebook, GitHub, Twitter, Google Search
  • 7. REST Mapping Verb Path Action GET /products index GET /products/:id show POST /products create GET /products/:id/edit edit PUT /products/:id update DELETE /products/:id delete
  • 8. Configuration /app/models/product.rb /app/controllers/products_controller.rb class Product < ActiveRecord::Base class Products < ApplicationController end def index @products = Product.all end def show @product = Product.find params[:id] end config/routes.rb def update ... Meetup::Application.routes.draw do |map| end resources :products ... end end
  • 9. Using resource /app/models/user.rb class User < ActiveResource::Base site.url = “http://api.twitter.com” end /app/controller/user_controller.rb class UserController < ActionController::Base self.site = “http://api.twitter.com” self.element_name = “user” self.proxy = “...” self.timeout = 5 self.ssl_options = { :key => “...” } end
  • 10. Fitting for the occasion Product Product Model Controller
  • 11. Fitting for the occasion HTTP Product Product Model Controller Android UI / XML iPhone UI / XML XML JSON
  • 12. Respond to class ProductsController < Application def index @products = Product.all respond_to do |format| format.html # index.html.erb format.iphone # index.iphone.erb format.json { render :json => @products } format.xml { render :xml => @products} end end end
  • 13. Fitting for the occasion Product /products.html Product Model Controller /products.xml /products.iphone /products.rss /products.js
  • 14. Review /app/models /app/controllers /app/views /app/helpers
  • 15. Rendering render :xml => @products render :json => @products render :file => “../owners/owner.html.erb” render :text => “Hello World” render :update do |page| page.replace_html(“products”, :partial => product, :object=> @product) end
  • 16. Views Layout :header content index.html.erb :menu product #1 product #2 product #3 :footer
  • 17. Layout # layout.html.erb # index.html.erb <html> <body> <%= content_for :header do %> <div class=”header”> <span> BALABIT Products </span> <%= yield :header %> <% end %> </div> <div class=”content”> <%= content_for :menu do %> <div class=”menu”> <li>Special menu item</li> <%= yield :menu %> <% end %> </div> </div> <div class=”products”> <div class=”content”> ... <%= yield %> </div> </div> ...
  • 18. Partial /app/views/products/index.html.erb content #object render :partial => “product”, :object => ... product #1 #array render :partial => “product”, :collection => ... product #2 product #3 /app/views/products/_product.html.erb
  • 19. Partial # /app/views/products/index.html.erb <div class=”products”> <%= render :partial => “product”, :collection => @products %> /app/views/products/index.html.erb </div> content # /app/views/products/_product.html.erb #object <div class=”product”> <span class=”title”><%= product.name %></span> => render :partial => “product”, :object ... product #1 <span class=”owner”><%= product.owner %></span> </div>#array render :partial => “product”, :collection => ... product #2 # result <div class=”products”> <div class=”product”> product #3 <span class=”title”>SCB</span> <span class=”owner”>Marci</span> </div> </div> /app/views/products/_product.html.erb
  • 20. Helpers /app/views/products/index.html.erb /app/helpers/products_helper.rb <div> module ProductsHelper <span> Number of products: </span> <%= number_of_products(@product) %> def number_of_products( products ) <div> products.select{ |p| p.active? }.size end <% form_for @product, :remote => true do | f | %> <%= f.text_field :version %> end <% end %>
  • 21. Cache class ProductController < Application class ProductController < Application before_filter :authentication caches_page :index caches_action :index def index def index @products = Product.all @products = Product.all end end def create def create expire_page :action => :index expire_page :action => :index ... ... end end ... ... end end
  • 22. Cache <html> <body> <% cache do %> <div class=”menu”> <li>Show products</li> </div> <% end %> <% cache(:action => 'update', :action_suffix => 'products') do %> <div class=”products”> <%= render :partial => “product”, :collection => @products %> </div> <% end %> # expire_fragment( :controller => ‘products’, :action => 'index', :action_suffix => 'products')