Ruby on Rails For .Net Programmers

4,703 views
4,592 views

Published on

An introduction to Ruby on Rails for .NET programmers

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
4,703
On SlideShare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
229
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby on Rails For .Net Programmers

  1. 1. me http://shinydevelopment.com
  2. 2. Hype
  3. 3. “Ruby on Rails is astounding. Using it is like watching a kung-fu movie, where a dozen bad-ass frameworks prepare to beat up the little newcomer only to be handed their asses in a variety of imaginative ways.” Nathan Torkington
  4. 4. “Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days.” Tim O'Reilly
  5. 5. What is Ruby on Rails?
  6. 6. Ruby Language C# or VB.NET on Rails Framework ASP.NET
  7. 7. Ruby
  8. 8. Ruby is Object Oriented
  9. 9. > 2.next => 3 > “Hello”.reverse => “olleH” > 2.class => Fixnum > 2.class.class => Class
  10. 10. > 2.class => Fixnum > 2.class.superclass => Integer > 2.class.superclass.superclass => Numeric > 2.class.superclass.superclass.superclass => Object
  11. 11. Ruby is Readable
  12. 12. > 5.times { print quot;Hello quot; } Hello Hello Hello Hello Hello > print “Stuff” unless x.nil? => Stuff > [3, 5, 78, 2, 43].sort.reverse => [78, 43, 5, 3, 2] > 2.weeks.from_now.utc => Wed Dec 27 11:25:06 UTC 2006
  13. 13. > [1, 2].empty? => false > x.nil? => true
  14. 14. > arr = [5, 4, 3] > arr.sort => [3, 4, 5] # arr is still [5, 4, 3] > arr.sort! => [3, 4, 5] # arr is now [3, 4, 5]
  15. 15. Ruby is Dynamic
  16. 16. > Linguistics::use(:en) > quot;runsquot;.en.present_participle => quot;runningquot; > 5.en.ordinal => quot;5thquot; > quot;cowquot;.en.quantify(1005) => quot;thousands of cowsquot;
  17. 17. > animals = %w{dog cow ox chicken goose goat cow dog rooster llama pig goat dog cat cat dog cow goat goose goose ox alpaca} > puts quot;The farm has quot; + animals.en.conjunction => “The farm has four dogs, three cows, three geese, three goats, two oxen, two cats, a chicken, a rooster, a llama, a pig, and an alpaca”
  18. 18. class ReverseString def method_missing(method_name) return method_name.to_s.reverse end end > s = ReverseString.new > s.Hello_World => “dlroW_olleH”
  19. 19. Rails
  20. 20. “Ruby on Rails is an opinionated framework for developing web applications”
  21. 21. Convention over Configuration
  22. 22. Model Controller View
  23. 23. ActiveRecord ActionPack Model View & Controller ActiveSupport JavaScript Libraries Prototype & Script.aculo.us ActionMailer ActionWebService
  24. 24. Convention over Configuration
  25. 25. Table Class groups Group people Person string.pluralize ABC_usrdetails User table_name_prefix “ABC_” set_table_name “usrdetails”
  26. 26. Dynamic Scaffolding and Validations demo
  27. 27. Magic?
  28. 28. scaffold :customer
  29. 29. Ruby is Dynamic
  30. 30. Hey, have you seen my new Rails app? I can imagine! *sigh*
  31. 31. script / generate
  32. 32. More Magic?
  33. 33. Routing
  34. 34. URL http://localhost:3000/customer/show/2 Routes.rb map.connect ':controller/:action/:id'
  35. 35. ActiveRecord
  36. 36. “The essence of an Active Record is a domain model in which the classes match very closely the record structure of an underlying database. Each active record is responsible for saving and loading to the database and also for any domain logic that acts on the database” Martin Fowler
  37. 37. ActiveRecord ActionPack Model View & Controller MySQL PostgreSQL ActiveSupport JavaScript Libraries MS SQL - ADO Prototype & Script.aculo.us MS SQL - ODBC Oracle ActionMailer ActionWebService SQLite DB2
  38. 38. class Customer < ActiveRecord::Base end >> Customer.column_names => [quot;idquot;, quot;namequot;, quot;emailquot;, quot;notesquot;] >> Customer.columns_hash[quot;idquot;] => default=nil, text=false, null=false, sql_type=quot;int(11)quot;, primary=true, name=quot;idquot;, type=:integer, number=true
  39. 39. class Customer < ActiveRecord::Base end Customer.find(:all) Customer.find(1) Customer.find_by_email(‘bill@example.com’) Customer.find_by_email_or_name( ‘bill@example.com’, ‘Ben’)
  40. 40. class Customer < ActiveRecord::Base end Customer.new do |c| c.email = ‘bill@example.com’ c.name = ‘Bill’ c.save end Customer.delete(1)
  41. 41. ActiveRecord Relationships
  42. 42. Describe the relationship “A customer has many orders and an order belongs to a customer.”
  43. 43. has_many belongs_to
  44. 44. Database Relationships demo
  45. 45. More Magic?
  46. 46. Ruby is Dynamic
  47. 47. Orders id Customers customer_id id item name email quantity notes unit_price
  48. 48. customer = Customer.find(params[:id]) customer.orders.create(params[:order])
  49. 49. Migrations demo
  50. 50. Capistrano
  51. 51. What next?
  52. 52. Try Ruby http://tryruby.hobix.com
  53. 53. Instant Rails http://instantrails.rubyforge.org
  54. 54. Locomotive http://locomotive.raaum.org/
  55. 55. SubSonic http://www.codeplex.com/Wiki/View.aspx? ProjectName=actionpackext Castle Project http://www.castleproject.org/
  56. 56. IronRuby
  57. 57. Newcastle Ruby on Rails User Group
  58. 58. Thank You dave.verwer@shinydevelopment.com

×