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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With