Home>
I am making a posting function with rails.
The following error occurs when executing the create method.
Error message
No route matches {: action =>"show",: controller =>"books",: id =>nil}, missing required keys: [: id]
### Applicable source code
Description in # books.controller #
Def new
@book = Book.new
end
def create
@book = Book.new (book_params)
@ book.save
redirect_to book_path (@ book.id)
end
~~~~ Abbreviation ~~~~
private
def book_params
params.require (: book) .permit (: Title,: Opinion)
end
end
Description in # books/view/_new.book.html.erb #
New book
<% = form_for: book, url: books_path do | f |%>
<P>Title</P>
<p>
<% = f.text_field: Title%>
</p>
<P>Opinion</P>
<p>
<% = f.text_area: Opinion%>
</p>
<p>
<% = f.submit%>
</p>
<% end%>
Enter the language name here
Source code
`` ```
I tried everything I looked up.
I understand that id is nil, but
I don't understand why the id is not given.
ruby 2.5.7
-
Answer # 1
Related articles
- ruby on rails - [rails] i want to solve "no route matches [post]"/messages/search "" of "routing error&
- no route matches [patch] i want to resolve the error ruby on rails
- ruby on rails 6 - error resolution for no route matches [delete]
- ruby on rails - missing required keys: i'm having trouble resolving the [: id] error
- ruby - routing error no route matches [post] appears
- ruby - no route matches [patch]
- ruby on rails - i don't understand template is missing
- ruby - routing error no route matches [post] i want to resolve "/ items/new"
- ruby - routing error no route matches [patch] i want to resolve "/ prototypes"
- ruby on rails - i want to write a test code that matches the rspec value
- ruby - when i do "rails s -e production" on ec2, i get "missing required arguments: aws_access_key_id"
- ruby - no route matches [get] "/ logout" resolution
- ruby on rails - i get a template is missing error in render
- ruby - rails tutorial chapter 2 (6th edition)
- ruby on rails - saved description in nested controller
- ruby on rails - access fails after seed after deploying to heroku
- ruby on rails - cart function routing error cannot be resolved
- ruby on rails - error in controller when transitioning with rails6 destory action
- ruby on rails - rails s can't
Trends
- 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
It seems that @ book.save has failed
Please check by temporarily setting it to @ book.save !.