rails 3.2中的自动保存问题

时间:2013-04-25 11:58:29

标签: ruby-on-rails-3 netzke

在给定的代码中,

class Supplier < ActiveRecord::Base  
  has_one :criteria, foreign_key: "crt_sup_id", :autosave => true   
  self.primary_key = 'sup_id'  
end  

class Criteria < ActiveRecord::Base  
  belongs_to :supplier, foreign_key: "crt_sup_id"  
  self.primary_key = 'crt_id'  
  self.table_name = 'criterias'  
end  
提交表单时,

自动保存功能无效。创建供应商记录但不创建标准。

表格代码

    class SupplierForm < Netzke::Basepack::Form
      def configure(c)
        c.model = 'Supplier'
        super
        c.items = [
          {field_label: "Name", name: :bname},
          {field_label: "Detail", name: :detail},
          {
            layout: :hbox, border: false, defaults: {border: false}, items: [
            {
              flex: 1,
              layout: :anchor,
              defaults: {anchor: "-8"},
              items: [
                {field_label: "Value 1", name: :criteria__val_one, xtype: :checkbox, nested_attribute: true},
                {field_label: "Value 2", name: :criteria__val_two, xtype: :checkbox, nested_attribute: true}
                ]
            }
            ]
          }
        ]
      end
    end  

控制器代码

def index
end  

1 个答案:

答案 0 :(得分:0)

在Netzke作者的帮助下解决。将criteria__val_one替换为criteria_val_one和 criteria__val_two with criteria_val_two。在模型类中创建虚拟属性。现在,可以使用这些虚拟属性访问表单中输入的所有值,并可以保存这些值。归功于 Max Gorin 。感谢伟大的工作(Netzke)