This article uses Ruby 2.6.5 installed on macOS Catalina 10.15.6.
--A helper method for sending information. --It will display the HTML required for input. --There are two ways to write form_with. ――The first is __ when the input information is saved in the database __, and the second is __ when the input information is not saved in the database __.
--model:
followed by __ a model class instance __.
--Create a text box with f.text_field
.
<%= form_with model: @book, local: true do |f| %>
<%= f.text_field :keyword, placeholder: "keyword", class: "search-input"%>
<%= f.submit "search", class: "search-btn" %>
<% end %>
--ʻUrl: `followed by __ information destination path __.
<%= form_with url: search_path, local: true do |f| %>
<%= f.text_field :keyword, placeholder: "keyword", class: "search-input"%>
<%= f.submit "search", class: "search-btn" %>
<% end %>
--For example, let's say the post controller has nested comment controller routing. ――In that case, the code looks like this. --_ You should describe two instances of the model class in the order of parent class and child class __.
<%= form_with model: [@post, @comment] do |f| %>
<%= f.text_field :comment%>
<%= f.submit %>
<% end %>
https://pikawaka.com/rails/form_with https://qiita.com/hmmrjn/items/24f3b8eade206ace17e2
Recommended Posts