gpt4 book ai didi

ruby - 使用 Formtastic 的单表继承

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:20 26 4
gpt4 key购买 nike

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

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 和谷歌,但没有找到任何有助于解决这个问题的方法。也许我没有正确解决问题,但我需要一些指导。有什么想法吗?

最佳答案

你试图将多个参数传递给它认为是多个字段的 due_date.inputs,你想使用 due_date.input (单数),就像这样:

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

关于ruby - 使用 Formtastic 的单表继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com