Lesson 3/7 - how do i create a route that maps /messages to index in routes file?

I assume I use routes.rb file but I dont see how to create that route?
This is the specific step I am stuck on
In the routes file, create a route that maps the URL /messages to the Messages controller’s index action

Hi Lohmub,

You’re correct, that’s the file :slight_smile:
You set a root like this:

root 'controller#action'

In this case, you’ll need to use

root 'messages#index'


Would you mind posting a link to the exercise you’re on?

1 Like

Thanks - I did get past that error and I’m now up to 4/7

1 Like

Thanks for the link - do you mind if I (or you could do it) move this back to the correct subcategory? Doing that will make it easier for people having the same question to find this :slight_smile:

I’m already past that point. I don’t want my position to be set back.

Don’t worry, moving this topic won’t affect any of your progress :slight_smile:
Is it OK with you if I move it?

In that case, feel free to move it back.

1 Like

Hi, this step has been very frustrating.
Even after copy/pasting your answer I get the error “No route matches “/messages””
I wish I could try to logically work through this, but the instructions [“In the routes file, create a route that maps the URL /messages to the Messages controller’s index action”] seem vague and introduce a number of new concepts with no explanation.

I’m sure that I’m doing something stupid, but the way the ruby and rails sections are written leave the unaware in the dark until after the right answer is figured out.


I found the full answer by reading other posts. It’s a bit of a red flag when dozens of people are confused on the exact same question. I think this is a step that could greatly use better directions.


@grumpygolding I’m glad you were able to figure out the problem!

I think that once you get some programming knowledge, even if it’s in a completely different language, you’ll have an easier time learning a new language, because I took the Learn Rails course after a bunch of other courses and didn’t have much trouble with it :slight_smile:

Feel free to send a message to Codecademy about the instructions (you can do that in the section below instructions on an exercise page) :slight_smile:

use this form…
get ‘controller’ => ‘controller#action’


Thank you, I have been stuck on what to do for the past 30 minutes. :smile:

1 Like

This is not working at all for me. It returns an error:

/var/lib/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:389:in `check_pending!’: (ActiveRecord::PendingMigrationError)

No idea how to get beyond this.



$ rake db:migrate

in the terminal.

that solution doesn’t work
Found this somewhere else and it works get '/messages' => 'messages#index'

1 Like

@rubysurfer14616 Thanks for pointing that out. I was thinking of something else when I wrote that answer I guess :slight_smile:

This solution doesn’t work for me either! It returns: “bash: messages: command not found”

::EDIT:: Wow, I feel so dumb haha! I was totally missing the part where it says “in the routes file”. Problem already solved :slightly_smiling:

1 Like

It helped me to read all the provided #comments# in the files, “routes.rb”, for instance

There you can see the provided example:

Example of regular route:

get ‘products/:id’ => ‘catalog#view’

so, if you’re completely stuck, the code would be

get ‘/message’ => ‘message#index’