DEV Community

Logan CoBell
Logan CoBell

Posted on

RRR

Today we learned about routing in Ruby and made our first Rails application, a remake of our Rock, Paper, Scissors game from the beginning of the course. There are many similarities with routing in express so this was a nice review of routing concepts and MVC architecture common to many frameworks. In Ruby on Rails all of our Routes are in our config/routes.rb file and look like this

get("/", { :controller => "application", :action => "page_you_want"})

The first argument of the get method is a string ("/") in this example.
The second argument is a Hash, in this example "page_you_want"

Next we have the application_controller (Controller/Action) in this file we find the controller, below is an example

render({ :template => "game_templates/scissors.html.erb"})

In this file we call the separate html file for the page, in this case scissors.html.erb for the basic structure of our page while embedding our logic in our application_controller.rb file. By using instance variables @variable syntax we can now use our variables in both our actual view file as well as our application_controller file making our code nice and DRY!

Here is a link to my GitHub repository RPS routing exercise

Top comments (0)