Take the 2-minute tour ×

I am sorry for asking what may be a remedial question, but in learning rails i was trying to follow along note for note in this tutorial:


I am fie to section 5.7 - showing the results of the post, as instructed I add this line to routes.rb


and the show method in posts_controller.rb:

class PostsController < ApplicationController
  def new

  def create
    @post = Post.new (post_params)
    redirect_to @post

  def show
    @post = Post.find(params[:id])

    def post_params


my routes.rb file is

Listing::Application.routes.draw do
  get "welcome/index"


  resources :posts

  root 'welcome#index'

Here is the error:

C:/Ruby-Projects/listing/config/routes.rb:4: syntax error, unexpected ':', expecting keyword_end post GET /posts/:id(.:format) posts#show ^

Rails.root: C:/Ruby-Projects/listing

Application Trace | Framework Trace | Full Trace This error occurred while loading the following files:

I am running rails 4.0, ruby 2.0 on 64 bit windows 8.

Admittedly I don't know what that line in the routes.rb is trying to do, but my goal was to type this in and pickup what i can, before digging into the subject full bore. i cut and pasted the line, typed it in, and tried changing a couple of things - without results.

I am tired, and feeling stupid, so I am here asking for your help.

Thank you in advance.

share|improve this question
Good question! I had this same problem, and I think your question is the only one in search space that addresses it. –  Trevor Alexander Aug 20 '13 at 8:27
add comment

2 Answers

up vote 11 down vote accepted

That line in section 5.7 is just showing you the output of rake routes, it's not meant to be in your config/routes.rb file.

The line resources :posts in routes.rb generates the show posts route for you, test it by removing the line: post GET /posts/:id(.:format) posts#show and then running rake routes on the command line.

share|improve this answer
Thank you.I am new to this, and for the life of me thought they wanted me to add that in routes. It should make following the remainder of the tutorial easier. I will accept after the deadline passes. –  akaphenom Jul 19 '13 at 1:56
No worries, I read through that tutorial and it's pretty unclear where that line came from and what you're supposed to do with it! –  Shevaun Jul 19 '13 at 2:08
Where is that line supposed to be? UPDATE: I see... it's supposed to be from the output of rake routes –  Randy James Jul 29 '13 at 1:59
I don't understand why it would show the output of rake routes? What does that have to do with submitting the form? –  AlxVallejo Feb 25 at 16:48
The tutorial is showing the output of rake routes in order to demonstrate that the show route exists, and that you need to create a corresponding action for the route in your controller. Submitting the form tries to redirect to the show action (redirect_to @post) –  Shevaun Feb 26 at 3:46
add comment

i'm new to the ruby world i have started learning it this afternoon :)

i had the same error as yours and i solved it by changing the way routes have been written to the suggested style within the routes.rb file.

instead of what have been written on that tutorials copy and past this into your routes.rb

Blog::Application.routes.draw do
  get "welcome/index"
 resources :posts
   root 'welcome#index'
  get    '/posts/:id(.:format)'  =>   'posts#show'
 get    '/posts(.:format)'       =>   'posts#index'

save and check your posts url as suggested on that tutorials


it should work for you.

share|improve this answer
You don't actually need those last two lines in your routes.rb file, because the line resources :posts generates all 7 routes for you: index, new, create, show, edit, update and destroy –  Shevaun Feb 26 at 3:48
add comment

Your Answer


