列存在时text_field中的未定义方法

时间:2016-12-12 15:48:28

标签: mysql ruby-on-rails

我有一个将要使用的表单,但是在打开表单时遇到了这个问题:

NoMethodError in Measures#new

Showing /home/supervisor/Rubyrails/Werkvergunning/app/views/measures/_form.html.erb where line #22 raised:

undefined method `measurement_type' for #<Measure:0x007f7bb3c5f978>
Did you mean?  measurement
               measurement?
               measurement=
               measurement_was

我绝对肯定该字段存在并且同一个表中的其他字段过去没有问题,所以它只是一个字段。 发生了什么,我该如何解决? _form:

<%= form_for(@measure) do |f| %>
  <% if @measure.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@measure.errors.count, "error") %> prohibited this measure from being saved:</h2>

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

  <div class="field">
    <%= f.label :measurement %><br>
    <%= f.text_field :measurement %>
  </div>
  <div class="field">
    <%= f.label :type %><br>
    <%# f.select :measurement_type, [['Product verklaring','product vrij verklaring'],['Elektrotechnische maatregel','Elektrotechnische maatregelen'],['Maatregel door vergunninghouder','maatregel door vergunninghouder'], ['brandpreventie', 'brandpreventie'], ['persoonnlijke bescherming', 'persoonlijke bescherming']] %>
    <%= f.text_field :measurement_type %>
  </div>
  <div class="field">
    <%= f.label :valid_from %><br>
    <%= f.date_select :valid_from %>
  </div>
  <div class="field">
    <%= f.label :valid_to %><br>
    <%= f.date_select :valid_to %>
  </div>
  <div class="field">
    <%= f.label :enquiry_measure_id %><br>
    <%= f.text_field :enquiry_measure_id %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

表格:

create_table "measures", force: :cascade do |t|
    t.string  "measurement",        limit: 255
    t.string  "measurement_type",   limit: 255
    t.date    "valid_from"
    t.date    "valid_to"
    t.integer "enquiry_measure_id", limit: 4
  end

谢谢

0 个答案:

没有答案