Rails : 如何更正表单上的未定义方法错误?
Rails : How to correct undefined method error on form?
我有一个表格 checkbox.Here 是表格 :
<div class="border-form-div">
<%= form_for(@user, class: "form-horizontal") do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.each do |attribute,message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<% if @user.role == "candidat" %>
<%= f.fields_for :profileable do |pf| %>
<div class="field">
<%= f.label :actif %> <br />
<%= f.check_box :actif, {}, true, false %> <br />
</div>
<% end %>
<br>
<div class="actions">
<%= f.submit "Mettre à jour",class: 'btn btn-primary' %>
</div>
<% end %>
</div>
我想去编辑页面:http://localhost:3000/users/3/edit
但我有以下错误:
undefined method `actif' for #<User:0x007fadc2674c48>
Extracted source (around line #35):
<div class="field">
<%= f.label :actif %> <br />
<%= f.check_box :actif, {}, true, false %> <br />
</div>
它似乎没有将actif 识别为属性。什么问题。 Actif 是在我的模型和表单中添加的 nw 字段。
把f.checkbox改成pf.checkbox我觉得。
<%= f.fields_for :profileable do |pf| %>
<div class="field">
<%= pf.label :actif %> <br />
<%= pf.check_box :actif, {}, true, false %> <br />
</div>
我有一个表格 checkbox.Here 是表格 :
<div class="border-form-div">
<%= form_for(@user, class: "form-horizontal") do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.each do |attribute,message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<% if @user.role == "candidat" %>
<%= f.fields_for :profileable do |pf| %>
<div class="field">
<%= f.label :actif %> <br />
<%= f.check_box :actif, {}, true, false %> <br />
</div>
<% end %>
<br>
<div class="actions">
<%= f.submit "Mettre à jour",class: 'btn btn-primary' %>
</div>
<% end %>
</div>
我想去编辑页面:http://localhost:3000/users/3/edit
但我有以下错误:
undefined method `actif' for #<User:0x007fadc2674c48>
Extracted source (around line #35):
<div class="field">
<%= f.label :actif %> <br />
<%= f.check_box :actif, {}, true, false %> <br />
</div>
它似乎没有将actif 识别为属性。什么问题。 Actif 是在我的模型和表单中添加的 nw 字段。
把f.checkbox改成pf.checkbox我觉得。
<%= f.fields_for :profileable do |pf| %>
<div class="field">
<%= pf.label :actif %> <br />
<%= pf.check_box :actif, {}, true, false %> <br />
</div>