我收到错误:
undefined form_with for #<#<Class:0x7ac62e0>:0x551e5a8>
in articles#new
以下文件中出现错误:new.html.erb
哪个有:
<%= form_with(model: [@article] , local: true) do |f| %>
<p>
<%= f.label :title %><enter code here`br>
<%= f.text_field :title %>
</p>
控制器articles_controller.rb
具有:
class ArticlesController < ApplicationController
def new
end
end
答案 0 :(得分:2)
您的控制器只有新命令,请参阅下面的示例,了解创建实例变量@article
articles_controller.rb
class ArticlesController < ApplicationController
def new
@article = Article.new
end
end
new.html.erb
<%= form_with @article do |f| %>
<%= f.label "Enter title: " %>
<%= f.text_field :title %>
<% end %>