Your SlideShare is downloading. ×
Ruby on Rails at UC Davis
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ruby on Rails at UC Davis

592
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
592
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby on RailsRuby on Rails at UC Davisat UC Davis Charlie Turner IET Mediaworks/CTS University of California, Davis July 30, 2007 cjturner@ucdavis.edu
  • 2. OutlineOutline  Background and Motivation  Introduction to Ruby on Rails  Rails applications (demo and ETRA)  Integration with campus services  Maintaining a Rails application  Recommendations  Questions and Discussion
  • 3. The Popularity ofThe Popularity of RoRRoR  Google ruby-on-rails -> returned 43,100,000 hits  Apple will ship Ruby on Rails with Mac OS X v10.5 "Leopard", scheduled for release in October, 2007.  Active open-source development community  Used in increasing number of production websites  O’Reilly Radar tracking book growth for last two years
  • 4. OO’’Reilly Categories 06->07Reilly Categories 06->07
  • 5. Ruby and Rails TimelineRuby and Rails Timeline 1993 Yukihiro “Matz” Matsumoto began Work on Ruby Ruby released to public Ruby on Rails developed by David Heinemeier Hansson and released to public To be shipped with Apple OS X 10.5 1995 2004 2007
  • 6. What is Ruby?What is Ruby?  Object-oriented scripting language − syntax inspired by Perl with Smalltalk-like OO features − shares some features with Python and Lisp  Everything is an object “hello”.length => 5 or 20.to_s => “20”  Define functions/methods def say_hello_to (name) puts “Hello #{name}” end  Arrays and hashes namevec.each {|n| puts “the name is #{n}”
  • 7. What is Rails?What is Rails?  Application framework − based on the Model-View-Controller (MVC) design pattern  Written in Ruby -> Ruby on Rails  Automate common web application operations − CRUD = Create, Read, Update, Delete  Based on an object-relational model (ORM) for database access  Favor convention over configuration − Scaffolding = standardized code layout, model and method names
  • 8. Model-View-ControllerModel-View-Controller (MVC) Architecture(MVC) Architecture database browser routing controllers views models
  • 9. Object Relational ModelObject Relational Model  Standard ORM Model − Database tables map to ruby classes − Table rows map to class objects − Row columns map to object attributes  Active Record = Rails ORM − Additional methods for search, sort, validation, etc. − Relationships between tables (foreign keys)  Has_one  Belongs_to  Has_and_belongs_to_many
  • 10. Simple Grant DB in RailsSimple Grant DB in Rails  Create Rails application − % rails etras  Configure Database − create database etras_development and grant access permissions − edit config/database.yml, updating username & password for database  Create Model and migration file − % script/generate model grant − edit file db/migrate/001_create_grants.rb adding table rows − % rake migrate  Create most basic controller − % script/generate controller admin − Edit app/controller/admin_controller.rb adding "scaffold :grant"  Start built-in WEBrick web server − % script/server  Point Browser to application root − http://localhost:3000/admin
  • 11. Grants List ViewGrants List View
  • 12. Grant Edit ViewGrant Edit View
  • 13. Grant Models (part)Grant Models (part) class GrantsController < ApplicationController def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @grant_pages, @grants = paginate :grants, :per_page => 10 end def show @grant = Grant.find(params[:id]) end end Autogenerated by scaffolding
  • 14. Grant list.Grant list.rhtmlrhtml <h1>Listing grants</h1> <table> <tr> <% for column in Grant.content_columns %> <th><%= column.human_name %></th> <% end %> </tr> <% for grant in @grants %> <tr> <% for column in Grant.content_columns %> <td><%=h grant.send(column.name) %></td> <% end %> <td><%= link_to 'Show', :action => 'show', :id => grant %></td> <td><%= link_to 'Edit', :action => 'edit', :id => grant %></td> <td><%= link_to 'Destroy', { :action => 'destroy', :id => grant }, :confirm => 'Are you sure?', :post => true %></td> </tr> <% end %> </table> <%= link_to 'Previous page', { :page => @grant_pages.current.previous } if @grant_pages.current.previous %> <%= link_to 'Next page', { :page => @grant_pages.current.next } if @grant_pages.current.next %> <br /> <%= link_to 'New grant', :action => 'new' %>
  • 15. Pitfalls to basic scaffoldPitfalls to basic scaffold
  • 16. After HTML escape addedAfter HTML escape added
  • 17. ETRA DatabaseETRA Database  Educational and Technology Resource Award (ETRA) − Application database used by UC Davis faculty/staff  All users identified (ldap) and authenticated (Kerberos)  Role-based access control − client, staff, producer, billing, developer  Supporting document attachment, comment tracking  Sorting, searching, grouping of applications  Email notification
  • 18. ETRA Application ListETRA Application List
  • 19. ETRA Ajax SearchETRA Ajax Search
  • 20. ETRA Show ApplicationETRA Show Application
  • 21. Integration with campusIntegration with campus servicesservices  Distributed Authentication (distauth) / CAS  LDAP  Email
  • 22. Distauth/CASDistauth/CAS IntegrationIntegration  Integrated with Apache I and II web server  Installed perl module connects to secure server for authentication  Protected on a directory level - not file by file  Sets browser cookie that is read by Ruby
  • 23. ApacheApache configconfig filefile
  • 24. Distauth/CASDistauth/CAS IntegrationIntegration
  • 25. LDAP accessLDAP access
  • 26. email notification (sample)email notification (sample)
  • 27. email notification (view)email notification (view)
  • 28. Experiences maintainingExperiences maintaining the ETRAthe ETRA RoRRoR ApplicationApplication  Stylesheet changes  Adding control menus  Bookmark bug  Database normalization
  • 29. StylesheetStylesheet ChangesChanges
  • 30. StylesheetStylesheet changeschanges
  • 31. Adding ASC/DESC MenuAdding ASC/DESC Menu
  • 32. ASC/DESC controller codeASC/DESC controller code
  • 33. ASC/DESC View codeASC/DESC View code
  • 34. Bookmark BugBookmark Bug  Client access highly restricted  Staff originally routed to application listing  Original authentication occurred in one place  Rails uses mod_rewrite − model/method/id − E.g. xyz.ucdavis.edu/show/user/12 − New routings visible to browser and can be bookmarked  Insufficient authentication/identification along all routes
  • 35. Bookmark -Bookmark - before_filterbefore_filter
  • 36. Deployment IssuesDeployment Issues  Rails new enough that some areas still debated  Heavy-weight runtime environment − Ongoing search for faster web server configuration − Multiple web server options: WEBrick, lighttpd, apache − Fastcgi, fcgi, proxying  Requires mod_rewrite − Increased complexity in apache config files − Can interact with apache CAS/distauth modules − Active development with mongrel, capistrano
  • 37. When to use RailsWhen to use Rails……  Python paradox (Paul Graham) − If a company chooses to write its software in a comparatively esoteric language, they'll be able to hire better programmers, because they'll attract only those who cared enough to learn it. And for programmers the paradox is even more pronounced: the language to learn, if you want to get a good job, is a language that people don't learn merely to get a job. (Paul Graham http://www.paulgraham.com/pypar.html) Investment Payoff CRUD applications Complex skins, Integration with external Services, deviations from Standard CRUD models Extended Maintenance
  • 38. RoRRoR ResourcesResources  Ruby On Rails − http://www.rubyonrails.org/ − See blog video (15 minutes)  Ruby Website − http://www.ruby-lang.org/en/  Ruby Forge − http://rubyforge.org/  Ruby Wikipedia page − http://en.wikipedia.org/wiki/Ruby_programming_language  Programming Ruby − http://www.ruby-doc.org/docs/ProgrammingRuby/  Ruby Central − http://www.rubycentral.org/