Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

netzke - Autosave issue in rails 3.2

In the given code,

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.

Form code

    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  

Controller code

def index
end  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...