在Rails和Paperclip中未定义的局部变量或方法`f'

时间:2021-06-25 23:52:40

I'm trying to create a new map, and it's not working out so far:

我正在尝试创建一个新的地图,到目前为止还没有成功:

undefined local variable or method `f' for #<#<Class:0x007ff46c0b12c0>:0x007ff46d777ba8>

I'm using Paperclip. The new page form:

我正在使用Paperclip。新的页面形式:

<%= form_for @map, :url => maps_path, :html => { :multipart => true } do |form| %>
  <% if @map.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@map.errors.count, "error") %> prohibited this map from being saved:</h2>

      <ul>
      <% @map.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :carname %><br />
    <%= f.text_field :carname %>
  </div>
    <%= form.file_field :map %>
  <div class="field">
    <%= f.label :criticalcomponentlocations %><br />
    <%= f.text_area :criticalcomponentlocations %>
  </div>
  <div class="field">
    <%= f.label :warnings %><br />
    <%= f.text_area :warnings %>
  </div>
  <div class="field">
    <%= f.label :additionalinfo %><br />
    <%= f.text_area :additionalinfo %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>

<% end %>

1 个解决方案

#1


3  

Since you pass form variable to the block passed to form_for method, you should substitute f with form.

由于您将表单变量传递给传递给form_for方法的块,因此您应该用表单替换f。

#1


3  

Since you pass form variable to the block passed to form_for method, you should substitute f with form.

由于您将表单变量传递给传递给form_for方法的块,因此您应该用表单替换f。