Nested isn't working, another approach, add trans validations

User a transactions border, select the customer from a view of users and customers
This commit is contained in:
Jason Denney
2013-01-20 14:57:43 -05:00
parent 31935f6f7e
commit 1b7daa45ca
5 changed files with 74 additions and 49 deletions
+6 -11
View File
@@ -1,22 +1,17 @@
class Transaction < ActiveRecord::Base
acts_as_loggable
attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item,
:customer_attributes
attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item
belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id'
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
validates :vendor_id, :presence => true
validates :customer_id, :presence => { :message => "Choose a User or Customer"}
validates :customer_type, :presence => { :message => "Choose a User or Customer"}
validates :amount, :presence => true
validates :item, :presence => true
def to_s
"#{amount} #{item} #{bike_id}"