Help

why is it that every time I find a tutorial, there are errors in it so that it does not work and I end up learning nothing.

Honestly I don’t know how anybody learns these languages, cause to me there are no solid resources available.

Trying to do this tutorial http://guides.rubyonrails.org/getting_started.html#creating-posts

And I get stuck here on part 5.7 Showing Posts:

The first line says
post ``GET /posts/``:id``(.``:format``) posts``#show

``

before this step I was editing the file app/controllers/posts_controller.rb

So I have to assume since no other file was mentioned that I add it there, correct, is it me? am I reading this wrong.

where do I add it, at the end, the beginning??

Here is what the class looks like now:

class PostsController < ApplicationController

def new

end

def create
@post = Post.new(post_params)

@post.save
redirect_to @post
end

private
def post_params
params.require(:post).permit(:title, :text)
end

end

Someone please help, I really would like to complete a tutorial.

This is the error from the server:

                 C:/Sites/blog/app/controllers/posts_controller.rb:2: syntax error, unexpected ':', expecting keyword_end
post GET /posts/:id(.:format) posts#show
^

Rails.root: C:/Sites/blog

Application Trace | Framework Trace | Full Trace


Request

Parameters:

 {"utf8"=>"✓",
"authenticity_token"=>"jDk9SBoDDxg/gaTMf7bckQ3uCFLhd9GX69Iy7dluc0M=",
"post"=>{"title"=>"Testing",
"text"=>"Hello World"},
"commit"=>"Save Post"}


I found the snippet you're referring to.

Yes, that part is pretty confusing in the tutorial. This line isn't actual valid Ruby code:

"

post ||GET| |/posts/||:id||(.||:format||) posts||#show|

"

this is just the output you usually get when you run "rake routes" that indicates that the "show" action will be called in the PostsController instance when you perform a GET request to /posts/:id(.:format) (for example, /posts/23.json).

You should look at your routes at config/routes.rb. If you can't find the description above after running "rake routes" you should probably add some line to your routes.rb like this:

get 'posts/:id(.:format)' => 'posts#show'

I hope that helps you.

The guide should really be revised but I don't think I'm the right person to do so as I don't know the original intention of the author for that part...

Good luck,
Rodrigo.

Hi Michelle,

Did the suggestion from Rodrigo fix your problem? I too have the same issue and it did not work for me.

Thanks.

Kaushik, please take a look at the edge guides:

http://edgeguides.rubyonrails.org/getting_started.html#showing-articles

It seems they fixed this particular section at least.

Best,
Rodrigo.