Rails redirect_to post

I saw an example in The Rails 3 Way book that says

redirect_to post 

Does this have any special meaning due to post , or is it just a bad choice for example, and post is just a domain object and redirects it to the URL for that object.

+4
source share
3 answers

I would need to see a complete example for a complete answer, but I assume that the author simply chose "Post" as the name of one of the models and did not understand that this could cause confusion with the POST reader.

As part of the HTTP protocol ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ), you cannot actually redirect the POST action. Or, more explicitly, no matter what destination you are redirecting to, you need to return using the GET method.

Hope this helps!

+7
source

Take a look at the Rails Routing Guide , then it should be clear why this is normal.

Also, if you want to view the routes for your application:

 cd path/to/your/app rake routes 

Here are the routes available in your application.

+1
source

you need Post resource and corresponding routes in config / routes.rb

just do "rails g resource post title: string content: text", for example, to create it. the route in the "redirect_to post" is processed dynamically. an instance of the post message is passed as an argument to the redirect_to method, as a result of which the page is redirected to the # show action message and passes the identifier of this Post instance. he "solves magic"

0
source

Source: https://habr.com/ru/post/1433079/


All Articles