0

我正在尝试获取一个项目表格来构建几个(最多 12 个)志愿者时间块的第一个(开始)时间。

project.rb

class Project < ActiveRecord::Base
  attr_accessible :title, ...
  has_many :vol_times, :dependent => destroy
  accepts_nested_attributes_for :vol_times, :reject_if => lambda { |a| a[:start_time].blank? }, :allow_destroy => true
  ...
end

vol_time.rb

class Vol_time < ActiveRecord::Base
  attr_accessible :start_time, ...
  belongs_to :project
end

ProjectsController

class ProjectsController < ApplicationController

  before_filter :signed_in_user, only: :create
  ...
  def new
    @project = Project.new
    @user = current_user
    @project.vol_times.build
  end
  ...
end

Vol_Times Controller

class Vol_TimesController < ApplicationController
  def new
    @reward = Reward.new
  end
  ...
end

我的观点是这样的……

<%= form_for(@project) do |f| %>

<div class="form_field_block">
      <p class="form_label">&nbsp;&nbsp;Project Title</p>
    <%= f.text_field :title, :size => 40, :placeholder => " Project Title...", :class => "frm" %>
</div>
<div class="form_field_block">
  <p class="form_label">&nbsp;&nbsp;Project Sub-title</p>
    <%= f.text_field :sub_title, :size => 40, :placeholder => "  Project Sub-title...", :class => "frm" %>
</div>
<p class="clearing"></p>
<div class="form_field_block">
  <% f.fields_for :vol_times do |builder| %>
    <%= render :partial => 'start_time', :f => builder %>
      <% end %>
</div>    
<p class="clearing"></p>
<%= button_tag "btn_start_project.png", :class => "btn_save" %>
<% end %>

_partial看起来像这样...

<%= f.label :start_time, "Starting Time" %>
<%= f.text_field :start_time %>

当我查看该页面时,我看到了ERB 的包含<div>内容,但没有看到 ERB 的内容,它应该从_partial.

任何想法为什么这不起作用?我从 Ryan Bates 的 RailsCast #196 中得到了一般背景 -这里

4

1 回答 1

1

=fields_for. 它应该是

<%= f.fields_for :vol_times do |builder| %>
于 2013-03-06T07:12:11.797 回答