单表继承与Formtastic

时间:2011-07-14 11:59:49

标签: ruby ruby-on-rails-3 formtastic single-table-inheritance

所以我有两个从另一个继承的模型如下:

class OneTime < Step
  has_one :due_date
  accepts_nested_attributes_for :due_date
end

class Repeatable < Step
  has_many :due_dates
  accepts_nested_attributes_for :due_dates
end

class Step < ActiveRecord::Base
  belongs_to :goal
end

我还有另一个嵌套在子类中的模型:

class DueDate < ActiveRecord::Base
  belongs_to :step
end

然后我使用formtastic有这样的表格:

= semantic_form_for [@goal, @step], :url => goal_step_path(@goal, @step), :html => { :class => "ajax"} do |f|
  = f.inputs :id => "step_#{@step.id}_description", :class => "description" do
    = f.input :description, :input_html => { :autofocus => "autofocus"}
  = f.semantic_fields_for :due_date do |due_date|
    = due_date.inputs :date_due, :as => :string, :input_html => { :class => "datepicker"}, :label => "Due Date"
  = f.buttons do
    = f.commit_button

问题是,当我尝试加载该表单时,我收到以下错误:

Showing /Users/dc/launchtools/app/views/steps/_form.html.haml where line #4 raised:

SQLite3::SQLException: no such column: due_dates.one_time_id: SELECT  "due_dates".* FROM "due_dates" WHERE ("due_dates".one_time_id = 121) LIMIT 1
Extracted source (around line #4):

我已经尝试了很多不同的东西来解决它并且没有任何效果。我也搜索了stackoverflow和谷歌,但没有发现任何有助于解决这个问题。也许我没有正确地解决问题,但我需要一些方向。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您尝试将多个参数传递给它认为是多个字段的due_date.inputs,您想要使用due_date.input(单数),如下所示:

= due_date.input :date_due, :as => :string, :input_html => { :class => "datepicker"}, :label => "Due Date"