[Ruby on Rails] Confirmation page creation


画面収録 2020-10-25 18.11.03.mov.gif

Development environment

ruby 2.5.7 Rails OS: macOS Catalina


This time, we will use scaffold to create a confirmation screen for the post.


$ rails g scaffold post body:string
$ rails db:migrate

Editing controller

Added the following.


def confirm
  @post = Post.new(post_params)

Edit route

Add the following


  resources :posts
  post 'posts/confirm', to: 'posts#confirm', as: 'confirm'

Edit view

In this state, if you post on the new screen, the create action will be executed and it will be saved. Therefore, from the new screen, write confirm to skip params.

@post %>Is deleted and described as follows.

#### **`erb:app/viwes/posts/new.html.erb`**

New Post

<%= form_with(model: @post, local: true, url: confirm_path) do |form| %> <% if @post.errors.any? %>

<%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:

  <% @post.errors.full_messages.each do |message| %>
    <li><%= message %></li>
  <% end %>

<% end %>

<%= form.label :body %> <%= form.text_field :body %>
<%= form.submit %>
<% end %>

<%= link_to 'Back', posts_path %>

 Create confirm.html.erb under app / viwes / posts.

#### **`<%= @post.body %>Display the posted content with`**
```body %>Display the posted content with

#### **`body %>Passes params to the create action in.`**
```<%= form.hidden_field 

#### **`erb:app/viwes/posts/confirm.html.erb`**
Confirmation of posted content

<%= @post.body %>

<%= form_with(model: @post, local: true) do |form| %>
<%= form.hidden_field :body %> <%= form.submit %>
<% end %> ```


I don't think there are many confirmation screens on the posting screen, I think that it is a display that you often see on the new registration screen, so This is an essential function if you want to implement functions such as membership registration.

Also, on twitter, technologies and ideas that are not uploaded to Qiita are also uploaded, so I would be grateful if you could follow me. Click here for details https://twitter.com/japwork

Recommended Posts

[Ruby on Rails] Confirmation page creation
Portfolio creation Ruby on Rails
Ruby on Rails application new creation command
(2021) Ruby on Rails administrator (admin) login creation
Ruby on Rails Elementary
Ruby on Rails basics
Ruby On Rails Association
[Beginner Procedure Manual 2] Ruby on Rails: Rails template creation
Determine the current page with Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
Ruby on Rails Overview (Beginner Summary)
[Ruby on Rails] Read try (: [],: key)
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function
Basic knowledge of Ruby on Rails
Progate Ruby on Rails5 Looking Back
[Ruby on Rails] Quickly display the page title in the browser
How to use Ruby on Rails
[Ruby on Rails] Add / Remove Columns
Ruby on Rails Japanese-English support i18n
[Ruby on Rails] CSV output function
Delete all the contents of the list page [Ruby on Rails]
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] What is Bcrypt?
Ruby On Rails devise routing conflict
[Ruby on Rails] Comment function implementation
[Ruby on Rails] DM, chat function
[Ruby on Rails] Convenient helper method
[Ruby on Rails] Stop "looping until ..."
[Ruby on Rails] Introduction of initial data
[Ruby on Rails] Search function (not selected)
[Rails] Addition of Ruby On Rails comment function
[Ruby on Rails] Creating an inquiry form
Ruby on Rails6 Practical Guide cp13 ~ cp15 [Memo]
[Ruby on Rails] View test with RSpec
[Ruby on Rails] Code check using Rubocop-airbnb
[Ruby on Rails] 1 model CRUD (Routing Main)
Ruby on Rails installation method [Mac edition]
[Ruby on Rails] model, controller terminal command
Let's summarize "MVC" of Ruby on Rails
[Ruby on Rails] About bundler (for beginners)
part of the syntax of ruby ​​on rails
Ruby on Rails6 Practical Guide cp7 ~ cp9 [Memo]
Ruby on Rails in Visual Studio Codespaces
[Ruby on Rails] Follow function implementation: Bidirectional
Notes on using FCM with Ruby on Rails
[Ruby on Rails] Controller test with RSpec
Deploy to Heroku [Ruby on Rails] Beginner
[Ruby on Rails] Image slideshow using Skippr