rubyonrails

40
Getting On Board Ruby on Getting On Board Ruby on Rails Rails Brian Hogan and Lillian Hillis Brian Hogan and Lillian Hillis University of Wisconsin – Eau Claire University of Wisconsin – Eau Claire

Upload: webuploader

Post on 12-May-2015

1.197 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: RubyonRails

Getting On Board Ruby on Getting On Board Ruby on RailsRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian Hillis

University of Wisconsin – Eau ClaireUniversity of Wisconsin – Eau Claire

Page 2: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Framework is two years oldFramework is two years old New way to develop web-based New way to develop web-based

applications applications Lots of converts from other languagesLots of converts from other languages

What's the buzzWhat's the buzz

Page 3: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

New web-to-database systemsNew web-to-database systems Migrations from existing PHP, ASP, or Migrations from existing PHP, ASP, or

Perl systemsPerl systems An alternative to non-Enterprise J2EE An alternative to non-Enterprise J2EE

systemssystems–Systems in that gap between simple Systems in that gap between simple scripts and complex enterprise systemsscripts and complex enterprise systems

When to use RailsWhen to use Rails

Page 4: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Simple scriptsSimple scripts Non-web projectsNon-web projects Complex systems with legacy Complex systems with legacy

databasesdatabases–Possible to do but you will lose productivity Possible to do but you will lose productivity gainsgains

When NOT to use RailsWhen NOT to use Rails

Page 5: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Web-based administrative Web-based administrative systems for administrative and systems for administrative and academic officesacademic offices–Housing and Residence LifeHousing and Residence Life–Student Health ServicesStudent Health Services–Music and Theater ArtsMusic and Theater Arts–Continuing EducationContinuing Education

Developed by student developersDeveloped by student developers–New developers every couple of yearsNew developers every couple of years–Team-based approach whenever possibleTeam-based approach whenever possible

How UW-Eau Claire Uses ItHow UW-Eau Claire Uses It

Page 6: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Rapid prototypingRapid prototyping Built-in testingBuilt-in testing Easy to maintain and upgradeEasy to maintain and upgrade Friendly user communityFriendly user community Easy to learn, embrace and extendEasy to learn, embrace and extend It’s agile!It’s agile!

Key BenefitsKey Benefits

Page 7: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Who’s Using RailsWho’s Using Rails

Penny ArcadePenny Arcade AListApartAListApart GustoGusto ShopifyShopify StrongspaceStrongspace Yakima-Herald TelegramYakima-Herald Telegram SubtopicSubtopic

Page 8: RubyonRails
Page 9: RubyonRails
Page 10: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Rails and the MVC PatternRails and the MVC Pattern

Model - View - ControllerModel - View - Controller Rails follows this pattern very Rails follows this pattern very

strictlystrictly Rails adds some extra Rails adds some extra

components to this patterncomponents to this pattern

Page 11: RubyonRails
Page 12: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

ModelsModels

■ Provide access to database tablesProvide access to database tables■ Contain business rulesContain business rules

■Record CRUD (Create, Read, Update, Record CRUD (Create, Read, Update, Delete)Delete)

■ An instance represents a row in a tableAn instance represents a row in a table■Grade model instance => one row Grade model instance => one row from ‘grades’ tablefrom ‘grades’ table

Page 13: RubyonRails

ModelModel

Models also define validations and Models also define validations and associations with other models.associations with other models.

Page 14: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

ModelsModels

Provided by mboffin.comProvided by mboffin.com

Page 15: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

ControllersControllers

Handle user requestsHandle user requests Retrieve data from modelsRetrieve data from models Invoke methods on modelsInvoke methods on models Send views and responses to usersSend views and responses to users Should contain no business logicShould contain no business logic

–Only flow controlOnly flow control

Page 16: RubyonRails

ControllersControllers

Here’s a basic controller action to display a blog postHere’s a basic controller action to display a blog post The URL would be /blog/show/1The URL would be /blog/show/1

Page 17: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

ViewsViews

The user screens or web pages of The user screens or web pages of your applicationsyour applications

Should contain no business logicShould contain no business logic Should not know about modelsShould not know about models Should contain very little Should contain very little

presentation logic whenever possiblepresentation logic whenever possible–Helpers are used for thisHelpers are used for this

Page 18: RubyonRails

ViewView

Views are similar to PHP or ASP pagesViews are similar to PHP or ASP pages Much more powerfulMuch more powerful Partials can be used to make our work easierPartials can be used to make our work easier

Page 19: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Rails-specific MVC componentsRails-specific MVC components

HelpersHelpers PartialsPartials LayoutsLayouts

Page 20: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

HelpersHelpers

Place to put presentation logicPlace to put presentation logic Available to Views and controllersAvailable to Views and controllers Rails has hundreds of built-in helpers Rails has hundreds of built-in helpers

for your viewsfor your views Easy to make your ownEasy to make your own

Page 21: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

PartialsPartials

Pieces of view code that can be reusedPieces of view code that can be reused–Can be applied to a collection of data!Can be applied to a collection of data!

Designed to be shared across multiple Designed to be shared across multiple viewsviews

ExamplesExamples–Form fields for Create and Update pagesForm fields for Create and Update pages–Search resultsSearch results–TablesTables–Table rowsTable rows

Page 22: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

LayoutsLayouts

Your templates are here.Your templates are here. Global or controller-specificGlobal or controller-specific No need for header and footer No need for header and footer

separationseparation–Rails reads the template last and places Rails reads the template last and places your application within the content regionyour application within the content region

Easy for designers to create layouts Easy for designers to create layouts without knowing Railswithout knowing Rails

Page 23: RubyonRails

LayoutsLayouts

Your rendered view is inserted here!

Page 24: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

MigrationsMigrations

Database-independent schema Database-independent schema definitiondefinition

Incrementally define your databaseIncrementally define your database Makes creation and recreation easy!Makes creation and recreation easy!I’m platform-

independent!

Page 25: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

ScaffoldingScaffolding

Generation of controllers and views Generation of controllers and views based on model definitionbased on model definition

Not meant for production use!Not meant for production use!–Needs tweaking firstNeeds tweaking first

Page 26: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Demo!Demo!

Page 27: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

ScalabilityScalability

Rails scales horizontallyRails scales horizontally When load is too high, bring up another When load is too high, bring up another

instance of the app & load balance your instance of the app & load balance your traffictraffic

Simple solutions for load-balancingSimple solutions for load-balancing–Apache 2.2 + mod_proxy_balanceApache 2.2 + mod_proxy_balance–PoundPound–Pen (Easy but no SSL support)Pen (Easy but no SSL support)–Lighttpd + mod_proxyLighttpd + mod_proxy

Page 28: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Scalability (continued)Scalability (continued)

Know your current requirementsKnow your current requirements ““100 users at the same time” isn’t a good 100 users at the same time” isn’t a good

benchmarkbenchmark–Simultaneous actions don’t happen all the timeSimultaneous actions don’t happen all the time

Think “requests per second”Think “requests per second”–Measure your existing apps and see how Rails Measure your existing apps and see how Rails compares.compares.

Your database is often the first scalability Your database is often the first scalability problem you’ll encounter in any web applicationproblem you’ll encounter in any web application–Databases can be clusteredDatabases can be clustered

Page 29: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

PerformancePerformance

Rails performs on par with other Rails performs on par with other languageslanguages

Slower on WindowsSlower on Windows–Limitation of compiled Ruby on WindowsLimitation of compiled Ruby on Windows

My tests on similar hardwareMy tests on similar hardware–7 req/sec to 35 req/sec on Windows7 req/sec to 35 req/sec on Windows–30 req/second to 150 req/second on Linux30 req/second to 150 req/second on Linux

Increase load by adding more Increase load by adding more “dispatchers” and load-balancing them“dispatchers” and load-balancing them

Page 30: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

DeploymentDeployment Linux is the best for deploymentLinux is the best for deployment Windows is supportedWindows is supported

–IIS won’t work well, if at allIIS won’t work well, if at all–Simple workarounds for this existSimple workarounds for this exist

Shared Hosting providers supporting RailsShared Hosting providers supporting Rails–Dreamhost (Great for personal stuff)Dreamhost (Great for personal stuff)–BlueHostBlueHost–RailsPlaygroundRailsPlayground

High-availability providers High-availability providers –RailsMachineRailsMachine–EngineYardEngineYard

Page 31: RubyonRails

DeploymentDeployment

Page 32: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

SecuritySecurity Security is a people problemSecurity is a people problem

–Developers must ensure security of their code and Developers must ensure security of their code and datadata

–System admins must keep their systems up to dateSystem admins must keep their systems up to date Rails has built-in mechanisms for preventing Rails has built-in mechanisms for preventing

SQL injection and XSSSQL injection and XSS Rails is as secure as any other server-side Rails is as secure as any other server-side

languagelanguage How secure is your platform underneath the How secure is your platform underneath the

web application?web application?

Page 33: RubyonRails
Page 34: RubyonRails

Choosing a Development Choosing a Development LanguageLanguage

MyDecisionHelperMyDecisionHelper– Helps you make critical decision using a Helps you make critical decision using a

patent-pending decision enginepatent-pending decision engine– Rails application developed by a team of Rails application developed by a team of

fivefive Two Rails programmers, one designer, one Two Rails programmers, one designer, one

consultant, and one market analyst, each consultant, and one market analyst, each working less than 20 hours per weekworking less than 20 hours per week

Developers are new to RailsDevelopers are new to Rails One developer made more progress in one One developer made more progress in one

weekend than in 3 months with .Net!weekend than in 3 months with .Net! What you see didn’t exist 2 months ago!What you see didn’t exist 2 months ago!

Page 35: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Resources - BooksResources - Books

Learn to ProgramLearn to Program (Chris Pine) (Chris Pine) Agile Web Development with RailsAgile Web Development with Rails

(Dave Thomas and David Heinemeier (Dave Thomas and David Heinemeier Hansson)Hansson)

Ruby for Rails, Ruby for Rails, Ruby techniques for Rails Ruby techniques for Rails developersdevelopers (David Black) (David Black)

Programming RubyProgramming Ruby (Dave Thomas) (Dave Thomas) Rails RecipesRails Recipes (Chad Fowler) (Chad Fowler)

Page 36: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Resources – Web SitesResources – Web Sites

www.rubyonrails.orgwww.rubyonrails.org wiki.rubyonrails.comwiki.rubyonrails.com api.rubyonrails.orgapi.rubyonrails.org www.uwec.edu/webdev/rorwww.uwec.edu/webdev/ror for for

additional resourcesadditional resources

Page 37: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Resources – Mailing ListResources – Mailing List

groups.google.com/group/rubyonrailsgroups.google.com/group/rubyonrails-talk-talk

Page 38: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On Getting On Board Ruby On RailsRails

Resources - OtherResources - Other

#rubyonrails on irc.freenode.org#rubyonrails on irc.freenode.org Email Brian any timeEmail Brian any time

[email protected]@uwec.edu–[email protected]@gmail.com

Contact Brian any time after the Contact Brian any time after the presentationpresentation

Page 39: RubyonRails

Brian Hogan and Lillian HillisBrian Hogan and Lillian HillisUniversity of Wisconsin-Eau University of Wisconsin-Eau ClaireClaire

Getting On Board Ruby On RailsGetting On Board Ruby On Rails

Thanks for coming!Thanks for coming!

Page 40: RubyonRails

Getting On Board Ruby on Getting On Board Ruby on RailsRails

Brian HoganBrian [email protected]@uwec.edudu

Lillian HillisLillian [email protected]@uwec.edu