SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Ruby on Rails
 Workshop
   Brad Midgley
About me

• U of U grad
• U of Colorado at Colorado Springs
• Worked in Linux--Turbolinux
• Worked in Java--U of U
• Rails/iPhone--Surgeworks
This is not a toy
Neither is Rails

• Programmers choose and enjoy it
• Huge collaboration benefit
• Open-source, freedom in license
• Inspiring other frameworks/languages
More Data Handling

• Using git
• Filtering at the model
• Sorting, driven by UI
• Filtering at the UI, search
Workshop up

• Project up-to-date
• Some data, user account
• Using/watching server log
• Launching console, interacting with app
Named scopes

• Spoiler?
• Enhancing the model
• Specify a subset of all rows
• Named scopes can be efficiently combined
Simple example
named_scope :family_friendly, :conditions => “rating in (‘G’, ‘PG’)”

Movie.family_friendly
Movie.family_friendly.all(:order => :genre)
Movie.family_friendly.all(:conditions => {:genre => 'Comedy'})
Create your own

• Think of a subset of users or movies
• Implement in app/models/*.rb
• Test using console
• Combine filters
Click-to-sort columns

• Very common to use ajax
• Often using a plugin
• A simple approach to start with
Non-ajax colsort

• http://garbageburrito.com/blog/entry/447/
  rails-super-cool-simple-column-sorting
• View renders an action with parameters to
  initiate sort
• Model watches for the parameters
Limitations?

• Doesn’t indicate sort order
• We’re not handling paging, will complicate it
• Let’s fix the first one
Sort order icon

• Poach up and down triangles
• No triangle if not sorting on this column
• Appropriate triangle for sort order
• Where does this code go?
Search

• Search on title for now
• UI component
• Server filter component
A special form

• Normally forms post
• Search has no side effects
• Search should be bookmarkable
• Make it a get, re-use the action we are on
Form front

<% form_tag(movies_path, :method => "get") do %>
 <%= text_field_tag(:s) %>
 <%= submit_tag("Search", :name => nil) %>
<% end %>
Form handler
• Watch params[:s]
• Try to keep existing code from today
• Remember we are passing a hash
• Implement this in controllers/
  movie_controller.rb
• Modify the result set in @movies
• GO
Hints
Hints

•   :conditions => ['title like ?', "%#{params[:s]}%"]
Hints

•   :conditions => ['title like ?', "%#{params[:s]}%"]

•   overlay with :order => ...
Hints

•   :conditions => ['title like ?', "%#{params[:s]}%"]

•   overlay with :order => ...

•   Construct a hash with only the :order and
    optionally add the :conditions => ...

Weitere ähnliche Inhalte

Was ist angesagt?

Frozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code SmellsFrozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code Smells
Dennis Ushakov
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
Thinkful
 

Was ist angesagt? (20)

Dev days Szeged 2014: Plugin system in drupal 8
Dev days Szeged 2014: Plugin system in drupal 8Dev days Szeged 2014: Plugin system in drupal 8
Dev days Szeged 2014: Plugin system in drupal 8
 
Web development basics (Part-3)
Web development basics (Part-3)Web development basics (Part-3)
Web development basics (Part-3)
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 
Haml. New HTML? (RU)
Haml. New HTML? (RU)Haml. New HTML? (RU)
Haml. New HTML? (RU)
 
JSLink for ITPros - SharePoint Saturday Jersey
JSLink for ITPros - SharePoint Saturday JerseyJSLink for ITPros - SharePoint Saturday Jersey
JSLink for ITPros - SharePoint Saturday Jersey
 
Beanshell scripting in Apache JMeter
Beanshell scripting in Apache JMeterBeanshell scripting in Apache JMeter
Beanshell scripting in Apache JMeter
 
Haml in 5 minutes
Haml in 5 minutesHaml in 5 minutes
Haml in 5 minutes
 
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUG
 
Run around Chrome Inspector
Run around Chrome Inspector Run around Chrome Inspector
Run around Chrome Inspector
 
CUCUMBER - Making BDD Fun
CUCUMBER - Making BDD FunCUCUMBER - Making BDD Fun
CUCUMBER - Making BDD Fun
 
Web development basics (Part-1)
Web development basics (Part-1)Web development basics (Part-1)
Web development basics (Part-1)
 
Frozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code SmellsFrozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code Smells
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子
 
Twig
TwigTwig
Twig
 
Web development basics (Part-2)
Web development basics (Part-2)Web development basics (Part-2)
Web development basics (Part-2)
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
 
Ch. 8 script free pages
Ch. 8 script free pagesCh. 8 script free pages
Ch. 8 script free pages
 

Ähnlich wie URUG Ruby on Rails Workshop - Sesssion 5

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
kevinvw
 

Ähnlich wie URUG Ruby on Rails Workshop - Sesssion 5 (20)

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephp
 
Cakeph pppt
Cakeph ppptCakeph pppt
Cakeph pppt
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
Automated Acceptance Testing from Scratch
Automated Acceptance Testing from ScratchAutomated Acceptance Testing from Scratch
Automated Acceptance Testing from Scratch
 
WordPress Theme and Plugin Optimization - WordPress Arvika March '14
WordPress Theme and Plugin Optimization - WordPress Arvika March '14WordPress Theme and Plugin Optimization - WordPress Arvika March '14
WordPress Theme and Plugin Optimization - WordPress Arvika March '14
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Webcomponents are your frameworks best friend
Webcomponents are your frameworks best friendWebcomponents are your frameworks best friend
Webcomponents are your frameworks best friend
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
RSpec on Rails Tutorial
RSpec on Rails TutorialRSpec on Rails Tutorial
RSpec on Rails Tutorial
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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)
 

URUG Ruby on Rails Workshop - Sesssion 5

  • 1. Ruby on Rails Workshop Brad Midgley
  • 2. About me • U of U grad • U of Colorado at Colorado Springs • Worked in Linux--Turbolinux • Worked in Java--U of U • Rails/iPhone--Surgeworks
  • 3. This is not a toy
  • 4. Neither is Rails • Programmers choose and enjoy it • Huge collaboration benefit • Open-source, freedom in license • Inspiring other frameworks/languages
  • 5. More Data Handling • Using git • Filtering at the model • Sorting, driven by UI • Filtering at the UI, search
  • 6. Workshop up • Project up-to-date • Some data, user account • Using/watching server log • Launching console, interacting with app
  • 7. Named scopes • Spoiler? • Enhancing the model • Specify a subset of all rows • Named scopes can be efficiently combined
  • 8. Simple example named_scope :family_friendly, :conditions => “rating in (‘G’, ‘PG’)” Movie.family_friendly Movie.family_friendly.all(:order => :genre) Movie.family_friendly.all(:conditions => {:genre => 'Comedy'})
  • 9. Create your own • Think of a subset of users or movies • Implement in app/models/*.rb • Test using console • Combine filters
  • 10. Click-to-sort columns • Very common to use ajax • Often using a plugin • A simple approach to start with
  • 11. Non-ajax colsort • http://garbageburrito.com/blog/entry/447/ rails-super-cool-simple-column-sorting • View renders an action with parameters to initiate sort • Model watches for the parameters
  • 12. Limitations? • Doesn’t indicate sort order • We’re not handling paging, will complicate it • Let’s fix the first one
  • 13. Sort order icon • Poach up and down triangles • No triangle if not sorting on this column • Appropriate triangle for sort order • Where does this code go?
  • 14. Search • Search on title for now • UI component • Server filter component
  • 15. A special form • Normally forms post • Search has no side effects • Search should be bookmarkable • Make it a get, re-use the action we are on
  • 16. Form front <% form_tag(movies_path, :method => "get") do %> <%= text_field_tag(:s) %> <%= submit_tag("Search", :name => nil) %> <% end %>
  • 17. Form handler • Watch params[:s] • Try to keep existing code from today • Remember we are passing a hash • Implement this in controllers/ movie_controller.rb • Modify the result set in @movies • GO
  • 18. Hints
  • 19. Hints • :conditions => ['title like ?', "%#{params[:s]}%"]
  • 20. Hints • :conditions => ['title like ?', "%#{params[:s]}%"] • overlay with :order => ...
  • 21. Hints • :conditions => ['title like ?', "%#{params[:s]}%"] • overlay with :order => ... • Construct a hash with only the :order and optionally add the :conditions => ...