1

For the guide that shows you how to set up a blog, I've gotten up to 5.7.
For this section it tells you how to show the article, but after following the steps I only get an error when attempting to run rails server.
It exactly says it is a syntax error in a routes line.
The line is "article get /articles/:id(.:format) articles#show" and the error is pointing to :id.
I'm not really sure what to do, I've looked at the routes section of the guide and I thought it was a valid line.

routes.rb contains

Rails.application.routes.draw do get 'welcome/index' resources :articles root 'welcome#index' article get /articles/:id(.:format) articles#show end 

The exact message I receive when I use the command rails server is:

blog/config/routes.rb:5: syntax error, unexpected ':', expecting keyword_end (SyntaxError) article get /articles/:id(.:format) article#show 
2
  • 2
    Add the error appearing in the console and the show.html.erb file on articles. Commented May 20, 2017 at 23:18
  • Post your routes.rb file please Commented May 20, 2017 at 23:18

3 Answers 3

3

The route you're trying to make is bad formatted, I could say you literally pasted the output from the rails routes command.

You need to specify firstly the HTTP verb, GET in this case, then the url which this will respond with, and then the controller and action.

From:

article get /articles/:id(.:format) articles#show 

Try with:

get '/articles/:id', to: 'articles#show' 
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, it's my first time. :) I did copy-paste, I thought that's what the guide was for!
0

Based on what you've put in your description, it looks like you're at the very least missing a hash rocket (=>) in one of your routes. However, as you've added the resources :articles line, I think the line that's produced this error could probably be removed altogether as the resources keyword will generate common routes like these automatically (please see the Rails API for more details).

Your routes.rb file should probably just look like this:

Rails.application.routes.draw do get 'welcome/index' resources :articles root 'welcome#index' end 

Alternatively, the route you're having trouble with could be rewritten as:

get "/articles/:id" => "articles#show" 

or in the way described in the guide:

get '/articles/:id', to: 'articles#show' 

2 Comments

Well yes (which is essentially what I wrote), but the OP is missing both of these...not to mention, the articles#show part of their route is missing quotation marks which I would also have expected to produce an error.
Kind of resent that you gave the winning answer to a guy who didn't even understand your question until after I'd answered it but I realise that's more the fault of the site than anything else. You're welcome.
0

If you remove this line:

article get /articles/:id(.:format) articles#show 

it should get ride of the error.

This line is not formatted correctly and it's trying to accomplish what is already being accomplished with the resources :articles line.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.