I want to redirect to the details page after updating the data on the edit page, but I get the error "No route matches [PATCH]"/books/1/books/1 "". I want to patch/books/1, but it doesn't work.
I reviewed the routing, but I didn't think there was anything unusual about it.
I would like to know how this kind of display appears.
Thank you.
route
Rails.application.routes.draw do
root to: "top # index"
post "/ books" =>"books # create"
get "/ books" =>"books # index"
get "/ books /: id" =>"books # show", as:'show'
get "/ books /: id/edit" =>"books # edit", as:'edit'
patch "/ books /: id" =>"books # update"
end
controller
class BooksController</pre>
<pre><code>view
Editing Book
<% = form_with model: @ book, url: "books/# {@ book.id}", local: true do | f |%>
title
<% = f.text_field: title%>
body
<% = f.text_area: body%>
<p><% = f.submit'Update Book'%></p>
<% end%>
<br><% = link_to "Show", show_path (@book)%>|<% = link_to "Back", "/ books"%></br>
-
Answer # 1
-
Answer # 2
Well, it seems to be an ad hoc answer if you can fix the current source code.
If you are willing to allow the time and the currently registered data to disappear, follow the steps below.Standard Rails implementationI recommend you to learn.
rails g scaffold mybook title: string body: text
rails db: migrate
Access http: // localhost: 3000/mybooks and check various operations
Compare mybooks controller with my books controller
Check the difference between mybooks and books in routes.rb
Compare the view files as well.
If you can understand it while looking at this article etc.
rails destroy scaffold mybook
Runrails db: migrate: reset
It will be the state before starting 1. by executing.
The important thing is not to be able to create apps using scaffold, but to make sure that you understand what the source of each line means and how it relates. think.
Related articles
- ruby on rails - no route matches , missing required keys: [: id] cannot be resolved
- ruby on rails - [rails] i want to solve "no route matches [post]"/messages/search "" of "routing error&
- ruby - no route matches [patch]
- ruby on rails 6 - routing error no route matches [patch] appears
- ruby - routing error no route matches [patch] i want to resolve "/ prototypes"
- ruby on rails 6 - error resolution for no route matches [delete]
- ruby - routing error no route matches [post] i want to resolve "/ items/new"
- ruby on rails - i want to write a test code that matches the rspec value
- ruby - routing error no route matches [post] appears
- ruby - no route matches [get] "/ logout" resolution
- ruby on rails - how to transition from the top page
- ruby on rails - i want to implement a function for administrator users to register luggage for general users in rails
- ruby on rails - things associated with a foreign key cannot be called in view
- ruby on rails 6 - environment construction of ruby on rails
- ruby on rails 5 - actioncontroller :: invalidauthenticitytoken cannot be resolved
- ruby on rails runtime error cannot be resolved
- ruby on rails - error in controller when transitioning with rails6 destory action
- ruby on rails - access fails after seed after deploying to heroku
- ruby on rails - missing required keys: i'm having trouble resolving the [: id] error
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
You have assembled the path yourself with the url: parameter you are passing to form_with.
Since it is a relative path, it may be better to add a slash at the beginning.
However, when developing with Ruby on Rails, it is recommended to use the URL helper instead of constructing the path directly. Reference: Rails guide