Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Everyday Rails

963 views

Published on

Slides by Błażej Hadzik, Ruby on Rails developer at @netguru covering intro to Ruby on Rails.. Originally created for the RoR workshop at Silesian University of Technology.

Published in: Technology
  • Be the first to comment

Everyday Rails

  1. 1. Everyday Rails brought by Blaze Hadzik and
  2. 2. Blaze Hadzik Ruby on Rails developer blazej.hadzik@netguru.co
  3. 3. netguru
  4. 4. Software house web&mobile
  5. 5. Team
  6. 6. Poznan, Warsaw, Gdansk, Krakow Australia, India, America, Brazil
  7. 7. #transparency
  8. 8. Workshops
  9. 9. 2 days
  10. 10. teams with mentors
  11. 11. fun
  12. 12. recruitment
  13. 13. /ˈruː.bi/
  14. 14. ‘Programming languages must feel natural to programmers.’ Matz
  15. 15. Ruby is a dynamic, scripting, object- oriented language...
  16. 16. :014 > 1.class => Fixnum :015 > (2.2).class => Float :016 > [].class => Array :017 > "Politechnika Slaska".class => String :018 > nil.class => NilClass :019 > “abc” + “d” => “abcd”
  17. 17. variables type local instance class global constant example name @name @@name $name NAME you don’t have to specify variable type
  18. 18. Variables a = 12 a.class # => Integer a = “polsl” a.class # => String a = [‘a’, ‘b’, ‘c’] a.class # => Array
  19. 19. Arrays and Hashes a = [ 'ant', 'bee', 'cat', 'dog', 'elk' ] a[0] # => "ant" a[3] # => "dog" # this is the same: a = %w{ ant bee cat dog elk } a[0] # => "ant" a[3] # => "dog"
  20. 20. Arrays and Hashes my_hash = { building: ‘school’, fruit: ‘orange’ } puts my_hash[:building] # => ‘school’
  21. 21. Symbols LOW_PRIORITY = 0 HIGH_PRIORITY = 1 priority = HIGH_PRIORITY vs priority = :high Symbols are simply constants that you don’t have to predeclare and that are guaranteed to be unique.
  22. 22. Control structures if/else statements case statements while structure
  23. 23. Blocks
  24. 24. Idioms
  25. 25. Idioms a, b = 1, 2 a += b a # => 3 @a ||= 1 # @a = 1 if @a.nil?
  26. 26. Classes, objects
  27. 27. Classes, objects class School def initialize(name) @name = name end end school = School.new(‘polsl’) p school # =>#<School:0x007fa301836160 @name="polsl">
  28. 28. Class Attributes class School def initialize(name) @name = name end def name=(name) @name = name end def name @name end end
  29. 29. Class Attributes attr_reader attr_writer attr_accessor
  30. 30. Access Control private protected public
  31. 31. Rails
  32. 32. ‘It is impossible not to notice Ruby on Rails.’ Martin Fowler
  33. 33. Ruby is language Rails is framework
  34. 34. DRY
  35. 35. Service Objects
  36. 36. Decorators
  37. 37. Convention over Configuration
  38. 38. REST
  39. 39. Structure
  40. 40. controllers models views routes.rb, database.yml Gemfile
  41. 41. MVC
  42. 42. controller model view browser DB routes web server
  43. 43. http://localhost:3000/
  44. 44. 127.0.0.1 - GET /index.html HTTP/1.0" 200 2326
  45. 45. get ‘/’, to: ‘welcome#index’
  46. 46. class WelcomeController < ApplicationController def index @posts = Post.all end end
  47. 47. class Post < ActiveRecord::Base end
  48. 48. class Post < ActiveRecord::Base end
  49. 49. class WelcomeController < ApplicationController def index @posts = Post.all end end
  50. 50. <ul> <% @posts.each do |post| %> <li> <%= post.title %> </li> <% end %> </ul>
  51. 51. <html> … <body> … <%= yield %> … </body> </html
  52. 52. http://localhost:3000/http://localhost:3000/
  53. 53. Let’s code
  54. 54. Thanks

×