Send information using hidden_field
■ Improved understanding of parameters ■ Understanding how to use hidden_field ■ Improving understanding of MVC
■ Mac OS catalina ■ Ruby on Rails (5.2.4.2) ■ Virtual Box:6.1 ■ Vagrant: 2.2.7
mac.terminal
$ rails new hidden_lesson
$ rails g scaffold Item name:string text:text price:integer amount:integer
$ rails db:migrate
config/routes.rb
root 'items#index'
post 'items/confirm' => 'items#confirm'
items/confirm.html.erb
<h3>Confirm page</h3>
<%= form_with model:@item do |form| %>
<div class="field">
<%= form.label :name %>
<%= @item.name %>
<%= form.hidden_field :name %>
</div>
<div class="field">
<%= form.label :text %>
<%= @item.text %>
<%= form.hidden_field :text %>
</div>
<div class="field">
<%= form.label :price %>
<%= @item.price %>
<%= form.hidden_field :price %>
</div>
<div class="field">
<%= form.label :amount %>
<%= @item.amount %>
<%= form.hidden_field :amount %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
items/_form.html.erb
<%= form_with(model: item, local: true) do |form| %> #Change this to ↓
<%= form_with(model: item, local: true, url: items_confirm_path) do |form| %>
that's all. The confirmation screen should be sandwiched before the product details screen transition.
■ About form_with https://qiita.com/tanaka-yu3/items/50f54f5d4f4b8dfe19f3
■ local: true https://qiita.com/hayulu/items/5bf26656d7433d406ede
■ Regarding confirmation screen creation https://qiita.com/tomoharutt/items/7959d28764912c64562f
■ When there are two arguments of form https://qiita.com/tanaka-yu3/items/94d2b9fccc9577756127
Recommended Posts