Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...