我根据 Hartl 的教程创建了一个 ToDoList,并遵循 guide添加标签系统。我一直关注到第 10 节,在那里他们要求我将我的 new.html.erb 文件修改为源代码中显示的代码。
<div class = 'col-md-8 offset-2'>
<h1 class = "text-center">New Blog Post</h1>
<%= simple_form_for @post, url: posts_path do |f| %>
<%= f.input :title %>
<%= f.input :content %>
<%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: {multiple: true} %>
<%= f.submit "Next", class: 'btn btn-lg btn-primary float-right' %>
<% end %>
</div>
因为我的 ToDoList 在 static_pages 上显示任务,所以我即兴创作并更改了 micropost_form.html.erb。
更改前:
<%= form_for(@micropost) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Add new task..." %>
</div>
<%= f.submit "Add Task", class: "btn btn-primary" %>
<% end %>
更改后:
<%= simple_form_for @micropost, url: microposts_path do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Add new task..." %>
<%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: {multiple: true} %>
</div>
<%= f.submit "Add Task", class: "btn btn-primary" %>
<% end %>
这产生了错误。
StaticPages#home 中的 NoMethodError
undefined method `simple_form_for' for #<#<Class:0x00007f8d6c84d4f0>:0x00007f8d6c833230>
Did you mean? simple_format
任何人都可以提出这里可能有什么问题吗?如果需要更多信息,请告诉我。
最佳答案
解决此类问题的最常见方法是重新启动服务器。你应该在安装 gem 之后总是这样做。你试过这个吗?
关于ruby-on-rails - 未定义的方法 `simple_form_for',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54279210/