SlideShare uma empresa Scribd logo
1 de 12
Baixar para ler offline
Cells
Simon Courtois - @happynoff
Problématique
     Comment partager un widget entre les pages du site ?




github: apotonick/cells
Solution à l’ancienne
   # app/controllers/application_controller.rb
   class ApplicationController < ActionController::Base
     before_filter :set_shopping_cart

    private

     def set_shopping_cart
       @shopping_cart = ShoppingCart.for_user(current_user)
     end
   end



                   # app/views/layouts/application.html.erb
                   <%= render 'shared/shopping_cart', shopping_cart: @shopping_cart %>




                                    # app/views/shared/_shopping_cart.html.erb
                                    <% if @shopping_cart %>
                                      # shopping cart rendering
                                    <% end %>




github: apotonick/cells
Solution avec Cells

  # app/views/layouts/application.html.erb
  <%= render_cell :shopping_cart, :display, user: current_user %>




              # app/cells/shopping_cart_cell.rb
              class ShoppingCartCell < Cell::Rails
                def display(opts)
                  @shopping_cart = ShoppingCart.for_user(opts[:user])
                  render
                end
              end



                                 # app/cells/shopping_cart/display.html.erb
                                 <% if @shopping_cart %>
                                   # shopping cart rendering
                                 <% end %>




github: apotonick/cells
Avantages


              Séparation des responsabilités
              Meilleure organisation du code
                 app/
                   cells/
                      shopping_cart/
                        display.html.erb
                     shopping_cart.rb




github: apotonick/cells
Aller plus loin - actions
    # app/cells/shopping_cart_cell.rb
    class ShoppingCartCell < Cell::Rails
      def display(opts)
        @shopping_cart = ShoppingCart.for_user(opts[:user])
        render
      end

      def count(opts)
        shopping_cart = ShoppingCart.for_user(opts[:user])
        @items_count = shopping_cart.items_count
        render
      end
    end




                 # app/views/layouts/application.html.erb
                 <%= render_cell :shopping_cart, :display, user: current_user %>
                 <%= render_cell :shopping_cart, :count, user: current_user %>




github: apotonick/cells
Aller plus loin - cache


                 # app/cells/shopping_cart_cell.rb
                 class ShoppingCartCell < Cell::Rails
                   cache :display, expires_in: 10.minutes

                   def display(opts)
                     # ...
                   end
                 end




github: apotonick/cells
Aller plus loin - cache


                 # app/cells/shopping_cart_cell.rb
                 class ShoppingCartCell < Cell::Rails
                   cache :display do |cell, opts|
                     opts[:user]
                   end
                   def display(opts)
                     # ...
                   end
                 end




github: apotonick/cells
Aller plus loin - helpers

         # app/cells/shopping_cart_cell.rb
         class ShoppingCartCell < Cell::Rails
           helper MyAwesomeHelper

           def display(opts)
             @shopping_cart = ShoppingCart.for_user(opts[:user])
             render
           end
         end




                             # app/cells/shopping_cart/display.html.erb
                             <%= do_something_awesome %>




github: apotonick/cells
Installation



                            gem ‘cells’


            $ rails generate cell shopping_cart display




         http://github.com/apotonick/cells




github: apotonick/cells
Questions ?



github: apotonick/cells
Merci !
@happynoff

Mais conteúdo relacionado

Destaque

How to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring EditionHow to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring Edition
Stephan Hochdörfer
 
Saa s multitenant database architecture
Saa s multitenant database architectureSaa s multitenant database architecture
Saa s multitenant database architecture
mmubashirkhan
 

Destaque (20)

เกม Ox
เกม Oxเกม Ox
เกม Ox
 
022006 zaidi badi
022006   zaidi badi022006   zaidi badi
022006 zaidi badi
 
Multi tenancy with mvc3 and entity framework
Multi tenancy with mvc3 and entity frameworkMulti tenancy with mvc3 and entity framework
Multi tenancy with mvc3 and entity framework
 
Create a simple multitenant application with entity framework
Create a simple multitenant application with entity frameworkCreate a simple multitenant application with entity framework
Create a simple multitenant application with entity framework
 
Multi-Tenancy in the Cloud
Multi-Tenancy in the CloudMulti-Tenancy in the Cloud
Multi-Tenancy in the Cloud
 
Multi-tenancy in Private Clouds
Multi-tenancy in Private CloudsMulti-tenancy in Private Clouds
Multi-tenancy in Private Clouds
 
Dependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSort
 
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EEConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
 
Monetizing Multi-Tenancy in SaaS by Sixteen Ventures. Presented at SaaS Unive...
Monetizing Multi-Tenancy in SaaS by Sixteen Ventures. Presented at SaaS Unive...Monetizing Multi-Tenancy in SaaS by Sixteen Ventures. Presented at SaaS Unive...
Monetizing Multi-Tenancy in SaaS by Sixteen Ventures. Presented at SaaS Unive...
 
Suportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EESuportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EE
 
Replacing church slide share
Replacing church slide shareReplacing church slide share
Replacing church slide share
 
JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...
JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...
JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...
 
Metering and Billing for Cloud Services
Metering and Billing for Cloud ServicesMetering and Billing for Cloud Services
Metering and Billing for Cloud Services
 
Webinar - Business Implications of SaaS Multi Tenancy
Webinar - Business Implications of SaaS Multi TenancyWebinar - Business Implications of SaaS Multi Tenancy
Webinar - Business Implications of SaaS Multi Tenancy
 
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EEJavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
 
Open Architecture for Developing Multitenant Software-as-a-Service Applications
Open Architecture for Developing Multitenant Software-as-a-Service ApplicationsOpen Architecture for Developing Multitenant Software-as-a-Service Applications
Open Architecture for Developing Multitenant Software-as-a-Service Applications
 
Multi-Tenant Approach
Multi-Tenant ApproachMulti-Tenant Approach
Multi-Tenant Approach
 
How to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring EditionHow to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring Edition
 
Multi Tenancy In The Cloud
Multi Tenancy In The CloudMulti Tenancy In The Cloud
Multi Tenancy In The Cloud
 
Saa s multitenant database architecture
Saa s multitenant database architectureSaa s multitenant database architecture
Saa s multitenant database architecture
 

Semelhante a Cells

Resource and view
Resource and viewResource and view
Resource and view
Papp Laszlo
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
New Relic
 
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
fiyuer
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 

Semelhante a Cells (20)

Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Resource and view
Resource and viewResource and view
Resource and view
 
Dash of ajax
Dash of ajaxDash of ajax
Dash of ajax
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 
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
 
Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Modularizing Rails Apps with Cells
Modularizing Rails Apps with CellsModularizing Rails Apps with Cells
Modularizing Rails Apps with Cells
 
Catalog display
Catalog displayCatalog display
Catalog display
 
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
 
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
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy Koshovyi
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
Rails 3
Rails 3Rails 3
Rails 3
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 

Mais de Simon Courtois

Mais de Simon Courtois (14)

Conseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussi
 
Organize your assets with Rails
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with Rails
 
Speed your Rails app creation with templates
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templates
 
How Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCII
 
Get Slim!
Get Slim!Get Slim!
Get Slim!
 
Fake your files - MemFs
Fake your files - MemFsFake your files - MemFs
Fake your files - MemFs
 
Rails is like Burger King
Rails is like Burger KingRails is like Burger King
Rails is like Burger King
 
REST with Her (and let Her take care of the REST)
REST with Her (and let Her take care of the REST)REST with Her (and let Her take care of the REST)
REST with Her (and let Her take care of the REST)
 
Ruby and DCI
Ruby and DCIRuby and DCI
Ruby and DCI
 
Mustdown
MustdownMustdown
Mustdown
 
Vos Regexps sont fausses !
Vos Regexps sont fausses !Vos Regexps sont fausses !
Vos Regexps sont fausses !
 
Ariane
ArianeAriane
Ariane
 
Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?
 
Commander
CommanderCommander
Commander
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Cells

  • 2. Problématique Comment partager un widget entre les pages du site ? github: apotonick/cells
  • 3. Solution à l’ancienne # app/controllers/application_controller.rb class ApplicationController < ActionController::Base before_filter :set_shopping_cart private def set_shopping_cart @shopping_cart = ShoppingCart.for_user(current_user) end end # app/views/layouts/application.html.erb <%= render 'shared/shopping_cart', shopping_cart: @shopping_cart %> # app/views/shared/_shopping_cart.html.erb <% if @shopping_cart %> # shopping cart rendering <% end %> github: apotonick/cells
  • 4. Solution avec Cells # app/views/layouts/application.html.erb <%= render_cell :shopping_cart, :display, user: current_user %> # app/cells/shopping_cart_cell.rb class ShoppingCartCell < Cell::Rails def display(opts) @shopping_cart = ShoppingCart.for_user(opts[:user]) render end end # app/cells/shopping_cart/display.html.erb <% if @shopping_cart %> # shopping cart rendering <% end %> github: apotonick/cells
  • 5. Avantages Séparation des responsabilités Meilleure organisation du code app/ cells/ shopping_cart/ display.html.erb shopping_cart.rb github: apotonick/cells
  • 6. Aller plus loin - actions # app/cells/shopping_cart_cell.rb class ShoppingCartCell < Cell::Rails def display(opts) @shopping_cart = ShoppingCart.for_user(opts[:user]) render end def count(opts) shopping_cart = ShoppingCart.for_user(opts[:user]) @items_count = shopping_cart.items_count render end end # app/views/layouts/application.html.erb <%= render_cell :shopping_cart, :display, user: current_user %> <%= render_cell :shopping_cart, :count, user: current_user %> github: apotonick/cells
  • 7. Aller plus loin - cache # app/cells/shopping_cart_cell.rb class ShoppingCartCell < Cell::Rails cache :display, expires_in: 10.minutes def display(opts) # ... end end github: apotonick/cells
  • 8. Aller plus loin - cache # app/cells/shopping_cart_cell.rb class ShoppingCartCell < Cell::Rails cache :display do |cell, opts| opts[:user] end def display(opts) # ... end end github: apotonick/cells
  • 9. Aller plus loin - helpers # app/cells/shopping_cart_cell.rb class ShoppingCartCell < Cell::Rails helper MyAwesomeHelper def display(opts) @shopping_cart = ShoppingCart.for_user(opts[:user]) render end end # app/cells/shopping_cart/display.html.erb <%= do_something_awesome %> github: apotonick/cells
  • 10. Installation gem ‘cells’ $ rails generate cell shopping_cart display http://github.com/apotonick/cells github: apotonick/cells