Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Rails

Intro to Rails

Brief introduction to Rails followed by a workshop.

Presented at: RailsGirls Bogotá 2015

92d08794b535e41a4082c57ea547546e?s=128

Sebastian Sogamoso

June 20, 2015
Tweet

Transcript

  1. Intro to Rails Sebastián Sogamoso @sebasoga

  2. Intro to Rails What is Rails?

  3. Intro to Rails Rails is a framework for creating web

    applications in Ruby
  4. Intro to Rails Rails is a framework for creating web

    applications in Ruby
  5. Intro to Rails Rails is a framework for creating web

    applications in Ruby
  6. Intro to Rails Rails is a framework for creating web

    applications in Ruby
  7. Intro to Rails What is a web page?

  8. Intro to Rails

  9. Intro to Rails

  10. Intro to Rails

  11. Intro to Rails

  12. Intro to Rails https://railsgirls.com/bogota

  13. Intro to Rails https://railsgirls.com/bogota

  14. Intro to Rails https://railsgirls.com/bogota Request

  15. Intro to Rails https://railsgirls.com/bogota Find file: cities/bogota.html

  16. Intro to Rails https://railsgirls.com/bogota <html lang=“eng”> <head> <meta charset=“utf-8”>…

  17. Intro to Rails https://railsgirls.com/bogota <html lang=“eng”> <head> <meta charset=“utf-8”>… Response

  18. Intro to Rails What is a web application?

  19. Intro to Rails

  20. Intro to Rails https://www.facebook.com/railsgirls <html lang=“eng”> <head> <meta charset=“utf-8”>… Response

    Request
  21. Intro to Rails m/railsgirls charset=“utf-8”>… • Get list of fans

    • Get list of comments • Order the comments by date • Get group photos • …
  22. Intro to Rails What is Rails?

  23. Intro to Rails Rails is a framework for creating web

    applications in Ruby
  24. Intro to Rails How does Rails do that?

  25. Intro to Rails By following the this ideas: • MVC

    pattern • Convention over configuration
  26. Intro to Rails MVC Pattern Model View Controller

  27. Intro to Rails Model

  28. Intro to Rails This class (model) represents a table in

    the database called “carts”
  29. Intro to Rails This class (model) represents a table in

    the database called “carts” Convention over configuration
  30. Intro to Rails Rails includes an ORM called ActiveRecord

  31. Intro to Rails Associations with other models

  32. Intro to Rails Validations of its own state

  33. Intro to Rails “Business logic”

  34. Intro to Rails Controller

  35. Intro to Rails Methods are called actions

  36. Intro to Rails Methods use models to access the database

  37. Intro to Rails Methods set instance variables

  38. Intro to Rails Can explicitly render or redirect

  39. Intro to Rails Can access the request parameters as a

    hash
  40. Intro to Rails View

  41. Intro to Rails Uses ERB, Rails default templating language

  42. Intro to Rails Regular HTML

  43. Intro to Rails Special tags to execute Ruby

  44. Intro to Rails Access to the instance variables set in

    the controller
  45. Intro to Rails How do they work together?

  46. Intro to Rails http://my-rails-app.com <html lang=“eng”> <head> <meta charset=“utf-8”>… Response

    Request
  47. Intro to Rails Model View Controller

  48. Intro to Rails Model View Controller

  49. Intro to Rails Model View Controller

  50. Intro to Rails Model View Controller

  51. Intro to Rails Model View Controller

  52. Intro to Rails Model View Controller

  53. Intro to Rails Model View Controller Router

  54. Intro to Rails How do I get started?

  55. Intro to Rails $ gem install rails

  56. Intro to Rails $ gem install rails Just the name

    for Ruby libraries
  57. Intro to Rails

  58. Intro to Rails Rails is modular, made out of other

    18 libraries
  59. Intro to Rails $ rails new my_app

  60. Intro to Rails $ rails new my_app The name of

    your Rails app
  61. Intro to Rails

  62. Intro to Rails Creates a bunch of files and then

    install the dependencies
  63. Intro to Rails

  64. Intro to Rails File with the list of libraries (gems)

    you want to use
  65. Intro to Rails Where app configuration files are

  66. Intro to Rails Where database schema and migrations are

  67. Intro to Rails Where tests go

  68. Intro to Rails Where your application code is $ cd

    app/
  69. Intro to Rails

  70. Intro to Rails Where CSS, JS and images go

  71. Intro to Rails Where controllers go

  72. Intro to Rails Helpers are “globally scoped” methods intended to

    be used mainly in views and controllers
  73. Intro to Rails Classes that make sending email easy

  74. Intro to Rails Where models go

  75. Intro to Rails Where views go

  76. Let’s see this in action! @sebasoga