Your SlideShare is downloading. ×
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
Rails by example
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 by example

1,202

Published on

For a demo to some colleagues, I created a Ruby on Rails demonstration. This presentation is used to show concepts, and illustrate the case. See http://changelos.com/2010/06/08/demoing-ruby-on-rails/ …

For a demo to some colleagues, I created a Ruby on Rails demonstration. This presentation is used to show concepts, and illustrate the case. See http://changelos.com/2010/06/08/demoing-ruby-on-rails/ for the full story.

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

No Downloads
Views
Total Views
1,202
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
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


  • Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.




























  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • Greatly increases readability!
  • I have been doing Ruby on Rails for about six weeks now; time for a quick introduction!
    This is not intended as a be-all-and-end-all presentation; I point out the things I find interesting or surprising.

    Image: http://shakti.trincoll.edu/~dmerrick/images/ruby.png
























  • Transcript

    • 1. Ruby on Rails
    • 2. Ruby (shorter now)
    • 3. Everything is an object 1.class # => Fixnum 'a'.class # => String :z.class # => Symbol class Foo end Foo.class # => Class Foo.new.class # => Foo
    • 4. Dynamically typed def do_stuff(thing) thing.do_the_stuff end class TheThing def do_the_stuff puts "Stuff was done!" end end do_stuff(TheThing.new)
    • 5. Arrays Array.new # => [] Array.new(3) # => [nil, nil, nil] [] # => [] a = [1,2,3] # => [1, 2, 3] a[0] = 'one' # => "one" a # => ["one", 2, 3] a[-1] # => 3 a[1..2] # => [2, 3]
    • 6. Hashes Hash.new # => {} {} # => {} h = {1 => "one", 2 => "two"} h[1] # => "one" h["1"] # => nil h[:one] = "einz" # => "einz" h[:one] # => "einz" h.keys # => [1, 2, :one] h.values # => ["one", "two", "einz"]
    • 7. Classes
    • 8. Classes class Pet attr_accessor :name def initialize(name) @name = name end def sit! puts "Wuff" end end
    • 9. Naming conventions CamelCased # Classes, modules with_underscores # methods, local variables @instance_variable @@class_variable $GLOBAL_VARIABLE
    • 10. Code blocks
    • 11. Code blocks [1,2,3,5,7].select {|x| x.even?} # => [2]
    • 12. Code blocks [1,2,3,5,7].select {|x| x.even?} # => [2] def do_random_nr_of_times &block nr = rand(10) for i in 1..nr yield end end
    • 13. Code blocks [1,2,3,5,7].select {|x| x.even?} # => [2] def do_random_nr_of_times &block nr = rand(10) for i in 1..nr yield end end do_random_nr_of_times { puts "bla" } # bla # bla # bla # => 1..3
    • 14. Optional language
    • 15. Optional language def my_method(data, options = {}) # ... end
    • 16. Optional language def my_method(data, options = {}) # ... end # Full signature my_method("bla", {:option => 'value', :two => 2})
    • 17. Optional language def my_method(data, options = {}) # ... end # Full signature my_method("bla", {:option => 'value', :two => 2}) # The last parameter a hash? implicit. my_method("bla", :option => 'value', :two => 2)
    • 18. Optional language def my_method(data, options = {}) # ... end # Full signature my_method("bla", {:option => 'value', :two => 2}) # The last parameter a hash? implicit. my_method("bla", :option => 'value', :two => 2) # Parentheses are optional my_method "bla", :option => 'value', :two => 2
    • 19. Optional language def my_method(data, options = {}) # ... end # Full signature my_method("bla", {:option => 'value', :two => 2}) # The last parameter a hash? implicit. my_method("bla", :option => 'value', :two => 2) # Parentheses are optional my_method "bla", :option => 'value', :two => 2 # As long as its unambiguous, it's OK
    • 20. Ruby on Rails
    • 21. Our case: a webshop
    • 22. Our case: a webshop
    • 23. What has rails built?
    • 24. What has rails built? • config • db • public • script • test
    • 25. REST in Rails
    • 26. REST in Rails # Listing # Reading # GET /things # GET /things/1 def index def show
    • 27. REST in Rails # Listing # Reading # GET /things # GET /things/1 def index def show # Creating # Updating # GET /things/new # GET /things/1/edit def new def edit # POST /things # PUT /things/1 def create def update
    • 28. REST in Rails # Listing # Reading # GET /things # GET /things/1 def index def show # Creating # Updating # GET /things/new # GET /things/1/edit def new def edit # POST /things # PUT /things/1 def create def update # Deleting # DELETE /things/1 # Actually: POST /things/1 with :destroy = true def destroy
    • 29. Layouts
    • 30. Layouts
    • 31. Filters
    • 32. The Shop controller
    • 33. Partials /things/_my_partial.html.erb <div id="my_div"> <p>Hello, <%= person %>!</p> </div>
    • 34. Partials /things/_my_partial.html.erb <div id="my_div"> <p>Hello, <%= person %>!</p> </div> <%= render :partial => 'my_partial', :locals => {:person => 'angelo'} %>
    • 35. Partials
    • 36. Partials
    • 37. The Cart
    • 38. The Cart
    • 39. REST in Rails # Listing # Reading # GET /things # GET /things/1 def index def show # Creating # Updating # GET /things/new # GET /things/1/edit def new def edit # POST /things # PUT /things/1 def create def update # Deleting # DELETE /things/1 # Actually: POST /things/1 with :destroy = true def destroy
    • 40. REST in Rails # Listing # Reading # GET /things # GET /things/1 def index def show # Creating # Updating # GET /things/new # GET /things/1/edit def new def edit # POST /things # PUT /things/1 def create def update # Deleting # DELETE /things/1 # Actually: POST /things/1 with :destroy = true def destroy
    • 41. Line and Order
    • 42. What was all that?
    • 43. What was all that? • Convention over configuration
    • 44. What was all that? • Convention over configuration • Mixed languages as necessary
    • 45. What was all that? • Convention over configuration • Mixed languages as necessary • Rapid development
    • 46. Resources http://pragprog.com/ titles/rails2
    • 47. Resources http://www.railscasts.com
    • 48. What haven’t I talked
    • 49. What haven’t I talked • AJAX-y things
    • 50. What haven’t I talked • AJAX-y things • Testing (RSpec)

    ×