Skip to content

Instantly share code, notes, and snippets.

View elrok123's full-sized avatar
🙃
:suspect:

Conner Stephen McCabe elrok123

🙃
:suspect:
View GitHub Profile
@elrok123
elrok123 / gist:5563805
Created May 12, 2013 14:45
Order class
class Order < ActiveRecord::Base
attr_accessible :client_id, :order_total
has_many :orderedproducts
has_many :products, through: :orderedproducts, :source => :product
has_one :client
before_save :generate_total
def generate_total
self.order_total = self.products.sum(:product_price)
@elrok123
elrok123 / gist:5563759
Created May 12, 2013 14:28
Order model
class Order < ActiveRecord::Base
attr_accessible :client_id, :order_total, :delivery_date
has_many :orderedproducts
has_many :products, through: :orderedproducts, :source => :product
has_one :client
before_save :generate_total
def generate_total
self.order_total = self.products.sum(:product_price)
@elrok123
elrok123 / gist:5563757
Created May 12, 2013 14:27
Double save sum error weirdness
irb(main):023:0> order.save
(0.1ms) BEGIN
(0.2ms) SELECT SUM(`products`.`product_price`) AS sum_id FROM `products` INNER JOIN `orderedproducts` ON `products`.`id` = `orderedproducts`.`product_id` WHERE `orderedproducts`.`order_id` IS NULL
SQL (0.1ms) INSERT INTO `orders` (`client_id`, `created_at`, `delivery_date`, `order_total`, `updated_at`) VALUES (1, '2013-05-12 14:25:21', '2013-07-24', 0.0, '2013-05-12 14:25:21')
SQL (0.1ms) INSERT INTO `orderedproducts` (`created_at`, `order_id`, `product_id`, `quantity_ordered`, `updated_at`) VALUES ('2013-05-12 14:25:21', 6, 1, NULL, '2013-05-12 14:25:21')
SQL (0.1ms) INSERT INTO `orderedproducts` (`created_at`, `order_id`, `product_id`, `quantity_ordered`, `updated_at`) VALUES ('2013-05-12 14:25:21', 6, 2, NULL, '2013-05-12 14:25:21')
(47.8ms) COMMIT
=> true
irb(main):024:0> order.save
(0.1ms) BEGIN
@elrok123
elrok123 / gist:5560017
Created May 11, 2013 13:45
order save error
irb(main):005:0> order.save
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `orders` (`ClientID`, `OrderTotal`, `created_at`, `updated_at`) VALUES (NULL, NULL, '2013-05-11 13:43:12', '2013-05-11 13:43:12')
(167.8ms) ROLLBACK
ActiveRecord::UnknownAttributeError: unknown attribute: order_id
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes'
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:236:in `block in build_record'
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/base.rb:500:in `initialize'
@elrok123
elrok123 / gist:5559993
Created May 11, 2013 13:36
Table descriptions
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ProductName | varchar(255) | YES | | NULL | |
| ProductPrice | float | YES | | NULL | |
| ProductQuantity | int(11) | YES | | NULL | |
| ProductSupplier | int(11) | YES | | NULL | |
| created_at | datetime | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
@elrok123
elrok123 / gist:5491023
Created April 30, 2013 18:55
CSS for custom font
@font-face {
font-family: 'harbara';
src: url('icomoon.eot');
src: url('icomoon.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}