ruby 2.5.7 Rails 22.214.171.124 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
Added the following.
def confirm @post = Post.new(post_params) end
Add the following
resources :posts post 'posts/confirm', to: 'posts#confirm', as: 'confirm'
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.
<%= form_with(model: @post, local: true, url: confirm_path) do |form| %> <% if @post.errors.any? %>
<ul> <% @post.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div>
<% 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`**
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