在mongoid中使用has_many时,我无法获取表单工作宽度集合
模型行:
int indexmyNumber = eintraegeListe.FindIndex(5, 10000, x => x.Contains("MyNumberMarker") && regexComplete.IsMatch(x));
模特团结:
if (indexmyNumber >= 0)
{
int myNumber = 0;
string myNumberString = regexComplete.Match(eintraegeListe[indexmyNumber]).Groups["number"].Value;
if (Int32.TryParse(myNumberString, out myNumber))
{
return myNumber;
}
}
我的表格是:
class Line
include Mongoid::Document
include Mongoid::Timestamps
field :observations
field :position, :type => Integer
field :status, :type => Integer
has_many :unities, :inverse_of => :unity
end
我收到此错误:未定义的方法`unity_id'对于#
答案 0 :(得分:1)
您的表单有问题:
<%= bootstrap_form_for @line do |f| %>
<div class="col-md-2">
<%= f.collection_select :unity_id, Unity.all, :id, :title %>
</div>
<% end %>
@line有很多unities,它没有unity_id字段。您也未在Line model中定义title
字段。
也许你可以这样做:
<%= bootstrap_form_for @unity do |f| %>
<div class="col-md-2">
<%= f.collection_select :line_id, Line.all, :id, :owner_name %>
</div>
<% end %>