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