[Hidden_field] Let's send information using rails hidden_field !!!!

【goal】

Send information using hidden_field

画面収録 2020-06-21 20.06.48.mov.gif

【merit】

■ Improved understanding of parameters ■ Understanding how to use hidden_field ■ Improving understanding of MVC

【Development environment】

■ Mac OS catalina ■ Ruby on Rails (5.2.4.2) ■ Virtual Box:6.1 ■ Vagrant: 2.2.7

【Implementation】

Application creation

mac.terminal


$ rails new hidden_lesson
$ rails g scaffold Item name:string text:text price:integer amount:integer
$ rails db:migrate 

Application adjustment

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.

[I want to read it together]

■ 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

[Hidden_field] Let's send information using rails hidden_field !!!!
[Enum] Let's improve the readability of data by using rails enum
Get Youtube channel information with Rails app (using Yt gem)
Search function using [rails] ransack
Try using view_component with rails
SNS authentication using Rails google
Send signed transactions using Web3j
[Rails] Save images using carrierwave
[RSpec] Let's use FactoryBot [Rails]
Japaneseize using i18n with Rails
[Rails] Japanese localization using rails-i18n
[Rails] Test code using Rspec
Organize Rails routing using draw
Ajax bookmark function using Rails
Error when using rails capybara
[Rails] Try using Faraday middleware
Detailed tips when using Rails
Deleting Exif information using sanselan
[Rails 6] Star-shaped review using Raty.js