Home>

ActionView :: MissingTemplate in Posts # new

I want to call a template for an input form.
An error will occur if there is no template.
No syntax error has occurred and
I'm also creating an empty instance.

(new.html.erb)
<h2>Add New Post</h2>
<% = render 'form'%>
(_ form.html.erb)
<% = form_for @post do | f |%>
...

Original source

(new.html.erb)
<h2>Add New Post</h2>
<% = form_for: post, url: posts_path do | f |%>
<p>
  <% = f.text_field: title, placeholder: 'enter title'%>
  <% end%>
</p>
<p>
  <% = f.text_area: body, placeholder: 'enter body text'%>
  <% end%>
</p>
<p>
  <% = f.submit%>
</p>
<% end%>


Also includes routes and controller

Rails.application.routes.draw do
resources: posts
end
class PostsController<ApplicationController
...
  def new
    @post = Post.new
  end
...

Please give me a professor

  • Answer # 1

    _form.htlm.erb
    ↑ It was an extension naming mistake.

  • Answer # 2

    I don't understand the cause well
    <% = render partial:'form'%>
    <% = render'posts/form'%>should work ...