Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Rails Routes and Resources A Route to an Index Action Creating a Route

Teri Dent
Teri Dent
11,515 Points

Rails definitions clarification

Starting at 2:43 you state that "we'll call the get method to set up a get route". When you use the term method here, are you talking about, for example:

def name
  puts "hello"
end

kind of method, or some other definition of method, such as the definition of the the GET method listed at https://robots.thoughtbot.com/back-to-basics-http-requests?

I went looking for rails documentation that listed what the get method syntax might be but I wasn't able to find a definition. It doesn't look like a "normal" method that you are passing a parameter due to the lack of parenthesis.

When you use the to: ... whatever that is...a key value pair maybe? Where would I find more information on the ...key/value pairs? I can send in routes (Or parameters or whatever?).

There is a lot here that I am being asked to take on faith that eventually I will get an explanation for, but as far as I can tell its never brought up again. This feels really sloppy and unfinished.

1 Answer

Natalie Tan
Natalie Tan
25,519 Points

In ruby, it is quite common place not omit paranthesis when passing parameters in.

With regards to we'll call the get method to set up a get route", he is referring to what he then types in on line 3 (3:49)

get '/pages', to: 'pages#index'

which you can read as get(/pages, {to: 'pages#index'})`

  • First parameter is the name of the route (/pages)
  • Second parameter is the key value pair. At this stage the most relevant key to learn is to:, with the value controller#action It tells rails what function to call when the route is hit. For 'pages#index, it will go to the pages controller and call the index function.

Official rails documentation is a good start: https://guides.rubyonrails.org/routing.html