Browse Source

Nested attributes on Transactions isn't working so well

denney-disable-on-select
Jason Denney 12 years ago
parent
commit
31935f6f7e
  1. 50
      app/components/transactions.rb
  2. 18
      app/models/transaction.rb

50
app/components/transactions.rb

@ -13,5 +13,55 @@ class Transactions < Netzke::Basepack::Grid
} }
} }
] ]
end
def default_fields_for_forms
bike_store = Bike.all.map { |b| [b.id, b.serial_number] }
user_store = User.all.map { |u| [u.id, u.to_s] }
[
:amount,
:item,
{ :name => :for_bike, :checkboxName => :bike_item, :inputValue => true, :title => "Selling a bike?",
:xtype => 'fieldset', :checkboxToggle => true, :collapsed => true, :items => [
{:xtype => 'combo', :no_binding => true, :name => :bike_id, :title => 'Bike', :fieldLabel => 'Bike', :store => bike_store}
]
},
{
xtype: 'fieldcontainer',
fieldLabel: 'Customer Type',
defaultType: 'radiofield',
defaults: {
flex: 1
},
layout: 'hbox',
items: [
{
no_binding: true,
boxLabel: 'Customer',
name: 'customer_type',
inputValue: 'Customer',
id: 'customer_radio'
},
{
no_binding: true,
boxLabel: 'User',
name: 'customer_type',
inputValue: 'User',
id: 'user_radio'
}
]
},
{ :name => :for_user, :checkboxName => :customer_type, :inputValue => true, :title => "Customer a User?",
:xtype => 'fieldset', :collapsible => true, :collapsed => true, :items => [
{:xtype => 'combo', :no_binding => true, :name => :customer_id, :title => 'User', :fieldLabel => 'User', :store => user_store}
]
},
{ :name => :for_customer, :checkboxName => :customer_type, :inputValue => true, :title => "New Customer?",
:xtype => 'fieldset', :collapsible => true, :collapsed => true, :items => [
{ :xtype => 'textfield', :no_binding => true, :name => 'customer[first_name]'},
]
}
]
end end
end end

18
app/models/transaction.rb

@ -1,8 +1,24 @@
class Transaction < ActiveRecord::Base class Transaction < ActiveRecord::Base
acts_as_loggable acts_as_loggable
attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item
attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item,
:customer_attributes
belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id' belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id'
belongs_to :bike belongs_to :bike
belongs_to :customer
accepts_nested_attributes_for :customer, allow_destroy: false
before_save :check_customer_type
def check_customer_type
puts "_________------------_________------------_________------------"
puts self.inspect
puts "_________------------_________------------_________------------"
end
def to_s
"#{amount} #{item} #{bike_id}"
end
end end

Loading…
Cancel
Save