Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails getting started 5.7

I'm programming for the first time in ruby and so I'm doing the 'getting started' tutorial from the official website:

http://guides.rubyonrails.org/getting_started.html

I have a problem with 5.7. The tutorial says:

If you submit the form again now, Rails will complain about not finding the show action. That's not very useful though, so let's add the show action before proceeding.

And then there is the following code:

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

But where do I have to put this code?

Thanks!

like image 502
Lorenzo Tassone Avatar asked Jul 01 '13 08:07

Lorenzo Tassone


1 Answers

What you've depicted is the show member for the posts resource routes. It's not actually code, but rather, a pattern for URL routing. You can see all your routes in this fashion by typing rake routes from the command line.

Breaking down the route:

post GET /posts/:id(.:format) posts#show
# `post` => named route name (available by default only to singular routes)
# `GET` => HTTP method
# `/posts/:id(.:format)` => path made accessible by route
# :id => specifies that the argument passed in as `:id` is available to the controller as `params[:id]`
# `posts#show` => controller is `posts`, action is `show`

You need to create a corresponding show controller action that the route will map to:

# app/controllers/posts_controller.rb
def show
  @post = Post.find(params[:id])
end
like image 174
zeantsoi Avatar answered Sep 28 '22 12:09

zeantsoi