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


#1

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


#2

Hi Lohmub,

You're correct, that's the file :)
You set a root like this:

root 'controller#action'

In this case, you'll need to use

root 'messages#index'

:)

Edit:
Would you mind posting a link to the exercise you're on?


#3

Thanks - I did get past that error and I'm now up to 4/7
https://www.codecademy.com/en/courses/learn-rails/lessons/one-model/exercises/one-model-view?action=lesson_resume


#4

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 :)


#5

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


#6

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


#7

In that case, feel free to move it back.


#8

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.


#9

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.


#10

@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 :)

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


#11

use this form...
get 'controller' => 'controller#action'


#12

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


#13

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.


#14

@techmastermike

Run

$ rake db:migrate

in the terminal.


#15

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


#16

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


#18

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:


#20

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'


#21