rails 3.2 中的自动保存问题 [英] Autosave issue in rails 3.2

查看:38
本文介绍了rails 3.2 中的自动保存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定的代码中,

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  

在我提交表单时自动保存不起作用.创建供应商记录但不创建标准.

autosave is not working when I am submitting the form. Supplier records are created but not Criteria.

    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  

推荐答案

已在 Netzke 作者的帮助下解决.用criteria_val_one 替换criteria__val_one 和标准__val_two 和标准_val_two.在模型类中创建虚拟属性.现在所有在表单中输入的值都可以通过这些虚拟属性访问并且可以保存.感谢 Max Gorin.感谢您的出色工作(Netzke)

Solved with the help of Netzke author. Replace criteria__val_one with criteria_val_one and criteria__val_two with criteria_val_two. Create virtual attributes in the model class. Now all the values entered in the form is accessible with these virtual attributes and can be saved. Credit goes to Max Gorin. Thanks for the great work (Netzke)

这篇关于rails 3.2 中的自动保存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆