新手入门,试图获得一对多关系并运行。我在模型和控制器中工作,但是我很难在视图中运行它。Ruby on Rails:一对多关系视图
<% unless @non_labor_expenses.nil? %>
<% count = 1 %>
<% for expense in @non_labor_expenses %>
<li>
<div class="label"><%= f.label :expense , "Expense" + count.to_s %></div>
<%= '$' + expense.amount.to_s + ' - ' + expense.description.to_s %>
</li>
<% count = count +1 %>
<% end %>
:
class Project < ActiveRecord::Base
has_many :non_labor_expenses
end
class NonLaborExpense < ActiveRecord::Base
belongs_to :project
end
我手动通过在控制器(编辑操作)加载@non_labor_expenses和可以拉动现有的数据在项目视图中像这样产生的所述non_labor_expense表的某些条目
我遇到的麻烦是将新的non_labor_expense条目添加到项目中。我应该能够管理后端的处理,但我甚至无法将该字段显示在表单中。
下面是我在哪里现在:
<li class="editable">
<div class="label"><%= f.label :non_labor_expenses %></div>
<%= f.text_field :non_labor_expenses %>
</li>
我知道我上面的代码看起来这样的事,但理想的表单字段会是这样的:
Expense Amount [text input]
Expense Description [text input]
我的完整形式的代码可以在这里找到:http://pastebin.com/m2b280b0f
你能发布所有的表单代码吗? – 2009-08-18 17:52:30
完整的表格代码:http://pastebin.com/m2b280b0f – easement 2009-08-18 18:00:11