mydomain.com/products
mydomain.com/photos/193
mydomain.com/signin
https://rps-rcav-your-username.c9users.io/scissors
, there are a lot of dots to connect!/scissors
.config/routes.rb
.get()
method, which has two arguments. The first argument is a String
that contains the address we want to support; in this case, "/scissors"
.get()
is a Hash
that tells Rails what to do when someone visits the address. The Hash
has two keys: :controller
and :action
.:controller
must go to the name of a Ruby class; in this case, we chose "game"
.:action
must go to the name of a Ruby method that we want Rails to execute when a user visits /scissors
; in this case, we chose "user_plays_scissors"
.app/controllers
folder. Files that contain controllers must always end in _controller.rb
, and begin with what we said in the route would be the name of the controller; in this case, game_controller.rb
.CamelCased
and always end in ...Controller < ApplicationController
. In this case, GameController < ApplicationController
.user_plays_scissors
.render()
method. The complete render()
method looks like this:render()
takes one argument, a String
. The string specifies the location of an Embedded Ruby HTML template to use to format the output. The first part of the string specifies the name of a folder, in this case game_templates
...play_scissors.html.erb
.@
when you create them. E.g. I define @comp_move = ["rock", "paper", "scissors"].sample
rather than comp_move
, and then @comp_move
is available in the view template (rather than dying when we reach the end
of the method, like a local variable would).app/views
that matches the name that we specified in the render()
statement.render()
statement..html.erb
template, produce a final plain .html
file, and send it back to the user's browser. Hurray!snake_case
; only class names are CamelCase
).app/controllers/
(be careful not to put the controller in app/controllers/concerns
.