SlideShare a Scribd company logo
1 of 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 => ...

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

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 => ...