Home>

We have created a site similar to twitter with rails.
Therefore, the move from the posting screen to the posting confirmation screen is not successful.

Error message
No route matches [POST] "/ posts/create"
post_controller.rb
class PostsController<ApplicationController
  def index
    @posts = Post.all.order (created_at:: desc)
  end
  def show
    @post = Post.find_by (id: params [: id])
  end
  def new
    @post = Post.new
  end
  def create
    @post = Post.new (content: params [: content])
    if params [: back]
      render: new
      return
    end
    unless @ post.valid?
      render: new
      return
    end
    if params [: send]
      @ post.save!
      flash [: notice] = "Post created"
      redirect_to '/ posts/index'
      return
    end
    render: confirm
  end
  def edit
    @post = Post.find_by (id: params [: id])
  end
  def update
    @post = Post.find_by (id: params [: id])
    @ post.content = params [: content]
    if @ post.save
    flash [: notice] = "Post edited"
    redirect_to ("/ posts/index")
    else
    render ("posts/edit")
    end
  end

  def destroy
    @post = Post.find_by (id: params [: id])
    @ post.destroy
    flash [: notice] = "Post deleted"
  redirect_to ("/ posts/index")
  end
  def confirm
    @post = Post.new (params [: post])
    if @ post.invalid?
     render: action =>"confirm"
    else
     render: action =>"index"
    end
  end
end
routes.rb
Rails.application.routes.draw do
  root "home # top"
  resources: sessions, only: [: new,: create,: destroy]
  resources: users
  resources: posts do
    collection do
      post: confirm
    end
  end
  get "about", to: "home # about"
end
new.html.erb (post screen)
<div>
  <div>
    <h1>Post</h1>
    <% = form_tag ('/ posts/create') do%>
    <div>
    <div>
    <% @ post.errors.full_messages.each do | message |%>
    <div>
    <% = message%>
    </div>
    <% end%>
    <% = text_area_tag: content, @ post.content%>
    <input type = "submit" value = "Confirm post">
    </div>
    </div>
    <% end%>
  </div>
</div>
confirm.html.erb (post confirmation screen)
<div>
  <div>
  <h1>Check your post</h1>
  <% = form_with (model: @post, url: posts_path, local: true) do | form |%>
  <div>
    <div>
    <div>
      <% = @ post.content%>
      <% = hidden_field_tag: content, @ post.content%>
    </div>
    <div>
      <% = submit_tag 'Submit', name: 'send', class: "btn btn-link"%>
    </div>
    <div>
      <% = submit_tag 'back', name: 'back', class: "btn btn-link"%>
    </div>
    </div>
    </div>
<% end%>
</div>
</did>