Your SlideShare is downloading. ×
Rails tools
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Rails tools

1,554
views

Published on

Reuven Lerner's presentation from Open Ruby Day in Herzliya, Israel on June 27th, 2010. I covered a few tools that are not part of Rails, but which help you with deployment,

Reuven Lerner's presentation from Open Ruby Day in Herzliya, Israel on June 27th, 2010. I covered a few tools that are not part of Rails, but which help you with deployment,

Published in: Technology

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

No Downloads
Views
Total Views
1,554
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
16
Comments
0
Likes
5
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. Rails-related tools Reuven M. Lerner Hi-Tech College June 27th, 2010
    • 2. You shipped! • Your Web application works • Everyone thinks that you’re a genius • Your new application is revolutionary • Too bad your parents still don’t know quite what you do for a living
    • 3. Just a few tasks remain • Find bottlenecks and optimize code • Find code problems (“smells”), and refactor • Learn about (and fix) bugs ASAP • Handle all of this without breaking a sweat
    • 4. Rails can’t help you • Rails helps you during development • But it doesn’t try to solve all problems • There are lots of add-ons that work with Rails, which make life much easier • This talk is about those tools
    • 5. • Deployment tool for Rails applications • Has been around for several years • “capify” in the root Rails directory • Creates small “Capfile” in root • Creates config/deploy.rb
    • 6. What does it do? • Run “cap deploy” on development machine • Capistrano: • Gets latest version from Git/SVN/CVS • Installs latest version in a new directory on production server(s) • Makes a “current” symlink to new dir
    • 7. So what? • Push to any number of servers • Keep around old versions, just in case • Always retrieve from version control • Add new recipes for your own needs • Adding/removing servers becomes trivial
    • 8. Deployment directory reuven@lerner:/var/www/www.modelingcommons.org/www$ ls -l total 12 lrwxrwxrwx 1 deploy deploy 60 2010-06-25 17:33 current - > /var/www/www.modelingcommons.org/www/releases/ 20100625143221 drwxrwxr-x 95 deploy deploy 4096 2010-06-25 17:32 releases drwxrwxr-x 6 deploy deploy 4096 2009-05-22 11:02 shared
    • 9. Releases directory drwxrwxr-x 17 deploy deploy 4096 2010-06-24 17:37 20100624143611 drwxrwxr-x 17 deploy deploy 4096 2010-06-24 18:09 20100624150829 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 10:45 20100625074334 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 11:07 20100625080541 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 16:01 20100625130006 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 16:38 20100625133723 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 16:48 20100625134648 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 17:09 20100625140815 drwxrwxr-x 17 deploy deploy 4096 2010-06-25 17:33 20100625143221
    • 10. A simple recipe namespace :rake do desc "Generate a sitemap on a remote server." task :generate_sitemap do run("cd #{deploy_to}/current; /usr/bin/rake sitemap:generate RAILS_ENV=production") end end
    • 11. My favorite feature cap deploy:rollback • It takes only a moment, because it’s just rewriting a symlink • Unnecessary if you never make mistakes
    • 12. Check your errors • “Exception notifier” plugin was popular for many years • Free plugin that sends e-mail on 500 errors
    • 13. • You can try it at hoptoadapp.com • Free version is good enough for many of my needs • Get e-mail exception information • Also get a Web-based interface • Mark bugs as having been resolved
    • 14. Can’t you just use logs? • Yes, but this is more convenient • “Similar errors” functionality is useful • Integration with GitHub, Lighthouse • Reset bug counts when you deploy • Besides, I like smiling frogs
    • 15. Check your code • Your code can always use improvement • Metacognition, reflection assist learning • Pair programming is good for this • Not appropriate for everyone • Get it from a computer, if not a person • At least you can turn the computer off
    • 16. Code-checking tools • Ruby has a large (and growing number) of tools that examine your code • Many of these are combined in the metric_fu gem • Gives you a good sense of the quality of your code • If you disagree, no one has to know!
    • 17. metric_fu includes • Churn — which files were changed the most in version control • Flay — looks for potential duplication across files • Flog — measures code complexity • Rcov — code coverage from your tests • Reek — looks for “code smells” • Roodi — looks for design issues • Saikuro — looks at cyclomatic complexity • Rails best practices — looks for common Rails problems
    • 18. Reek: Code smells • Duplication • Uncommunicative names • Control couple • Nested iterators • Feature envy • Simulated polymorphism
    • 19. What if you disagree? • Ignore Reek • Or think about it again • Or change the configuration • Or e-mail Kevin Rutherford • (Don’t just say, “What a stupid program.”)
    • 20. *****
    • 21. Rails best practices • New in metric_fu • Based on a presentation at a Shanghai Ruby discussion • http://github.com/flyerhzm/ rails_best_practices • Helps to keep bad practices in check
    • 22. Typical suggestions • Move code from view into controller • Move code from controller into model • Law of demeter (long.chain.of.method.calls) • Use before_filter • Add database index • Move finder to named scope
    • 23. *****
    • 24. Check your performance • Simple benchmarks can be put in code • I put all sorts of comments in views, logs • But that implies you know where to look! • Quick, what are the 5 slowest methods in your application? • How many people are affected by them?
    • 25. One option: RPM • New Relic RPM monitors performance • Your app sends info to it every so often • New Relic makes aggregate data available • Free version is often good enough • Paid versions are worthwhile if your business depends on the app!
    • 26. Summary • Rails is great for developing Web apps • But there is a whole ecosystem of tools that can help you to improve your apps even further • Many of them are free! • New ones emerge every month
    • 27. Thanks! • Israel.rb (Google group) • Ruby, Rails courses right here! • Call me: 054-496-8405 • E-mail me: reuven@lerner.co.il • Interrupt me: reuvenlerner (Skype/AIM)