Rubyon Rails

653 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
653
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rubyon Rails

  1. 1. Ruby on Rails The most awesome thing to hit the internet since Rick Astley UW – Eau Claire Web-Centric Programming May 30, 2009 Presenter: Kevin Gisi [email_address] Twitter: gisikw
  2. 2. About the Presenter <ul><li>Computer Engineering </li></ul><ul><li>LTS – Web Development </li></ul><ul><li>Independent Contractor </li></ul><ul><li>Co-founder of the Eau Claire Ruby User Group </li></ul><ul><li>Winner of the RailsRumble “Most Innovative” award </li></ul><ul><li>Pragmatic Programmers Author </li></ul>
  3. 3. What is Ruby? <ul><li>Developed in the 1990’s in Japan </li></ul><ul><li>C-based interpreted language </li></ul><ul><li>Dynamically (“duck”) typed </li></ul><ul><li>Based on Perl and Smalltalk </li></ul><ul><li>Many different implementations (YARV, JRuby, Rubinius, IronRuby, MacRuby) </li></ul><ul><li>Completely open-source </li></ul>
  4. 4. What is Rails? <ul><li>Web application framework </li></ul><ul><li>Extracted from 37Signals in 2004 </li></ul><ul><li>Model – View – Controller </li></ul><ul><li>Convention over Configuration </li></ul><ul><li>Don’t Repeat Yourself (DRY) </li></ul><ul><li>Representational State Transfer (REST) </li></ul><ul><li>Completely open-source </li></ul>
  5. 5. Convention: REST <ul><li>Everything is a resource </li></ul><ul><li>You Create (POST), Read (GET), Update (PUT), and Destroy (DELETE) resources </li></ul><ul><li>Also need New, and Edit pages </li></ul>
  6. 6. Convention: URLs <ul><li>URLs should be pretty! </li></ul><ul><li>Index /listings </li></ul><ul><li>New /listings/new </li></ul><ul><li>Show /listings/5 </li></ul><ul><li>Edit /listings/5/edit </li></ul><ul><li>Create /listings </li></ul><ul><li>Update /listings/5 </li></ul><ul><li>Destroy /listings/5 </li></ul>
  7. 7. Ruby on Rails Tools <ul><li>RubyGems – Package Manager </li></ul><ul><li>Plugins – Adds functionality </li></ul><ul><li>Generators – Writes code for you </li></ul><ul><li>Console – Access runtime environment </li></ul>
  8. 8. Server Structure Front-end Apache/Nginx Server – 5000 Mongrel Server – 5001 Mongrel Server – 5002 Mongrel Database
  9. 9. What Runs On Rails? <ul><li>Hulu </li></ul><ul><li>Twitter </li></ul><ul><li>37 Signals </li></ul><ul><li>Blinksale </li></ul><ul><li>Many UWEC Applications </li></ul>
  10. 10. 2-Minute Ruby <ul><li>Everything is an object </li></ul><ul><li>Anything other than false or nil is “true” </li></ul><ul><li>Functions always return something </li></ul><ul><li>Classes can be modified at runtime </li></ul><ul><li>@instance_variables </li></ul><ul><li>@@class_variables </li></ul><ul><li>CONSTANTS </li></ul>
  11. 11. 2-Minute Ruby <ul><li>Arrays [ ] </li></ul><ul><li>Ordered, dynamically sized </li></ul><ul><li>my_array << value </li></ul><ul><li>my_array[4] </li></ul><ul><li>my_array.pop </li></ul>
  12. 12. 2-Minute Ruby <ul><li>Hashes { } </li></ul><ul><li>Not ordered </li></ul><ul><li>Key, value pairs </li></ul><ul><li>Keys are traditionally :symbols </li></ul><ul><li>Awesome for methods </li></ul>
  13. 13. 2-Minute Ruby Methods def foo(params = {}) “ You said” + params[:message] end
  14. 14. 2-Minute Ruby <ul><li>Methods (continued) </li></ul><ul><li>mutate!, boolean?, assignment= </li></ul><ul><li>def method_missing </li></ul><ul><li>“ We don’t do that!” </li></ul><ul><li>end </li></ul>
  15. 15. 2-Minute Ruby Classes class Awesome attr_accessor :pie end a = Awesome.new a.pie
  16. 16. 2-Minute Ruby Blocks my_array.each do |value| puts “It was #{value}” end
  17. 17. 2-Minute Ruby Pretend I Didn’t Show You This eval(“foo = 5”)
  18. 18. 3-Minute Rails <ul><li>Models </li></ul><ul><li>Validations </li></ul><ul><li>Business logic </li></ul><ul><li>Other object methods </li></ul><ul><li>Anything that doesn’t go somewhere else </li></ul>
  19. 19. 3-Minute Rails <ul><li>Controllers </li></ul><ul><li>Before filters </li></ul><ul><li>Public actions </li></ul><ul><li>Keep them small! </li></ul>
  20. 20. 3-Minute Rails <ul><li>Views </li></ul><ul><li>Display </li></ul><ul><li>Mix of HTML and ERb (Embedded Ruby) </li></ul><ul><li>Avoid logic here! </li></ul>
  21. 21. 3-Minute Rails <ul><li>Helpers </li></ul><ul><li>Custom embedded Ruby: </li></ul><ul><li>def paypal </li></ul><ul><li>“ <form>Paypal donate code</form>” </li></ul><ul><li>end </li></ul>
  22. 22. Boo Slides! Let’s be awesome code monkeys instead!

×