Skip to content

Instantly share code, notes, and snippets.

class User < ActiveRecord::Base
belongs_to :roleable, :polymorphic => true
end
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :first_name
t.string :last_name
t.integer :age
t.timestamps
end
end
INSERT INTO `users` (`age`, `created_at`, `first_name`, `last_name`, `updated_at`)
VALUES (32, '2010-09-24 08:10:32', 'Juan', 'Perez', '2010-09-24 08:10:32')
#
# Script builded to ruby 1.9.1
#
require 'CSV'
class ArrayIterator
#
# Class ArrayIterator
# Implementation of Iterator pattern
#
$options['joins'] = array(
array('table' => 'books_tags',
'alias' => 'BooksTag',
'type' => 'inner',
'conditions' => array(
'Books.id = BooksTag.books_id' )),
array('table' => 'tags',
'alias' => 'Tag',
'type' => 'inner',
@products.each_with_index do |p, i|
p.update_attributes(:date_available => i.minutes.ago)
end
@jparbros
jparbros / representante_modelo.js
Created February 11, 2012 04:32
backbone.js ejemplo
window.Representante = Backbone.Model.extend({})
@jparbros
jparbros / gist:1796510
Created February 11, 2012 04:52
backbone.js ejemplo 2
window.Variant = Backbone.Model.extend({
url: function() {
if (this.id != null) {
return 'variants/' + this.id;
} else {
return 'variants';
}
},
addToCart: function() {
return alert('I was added to cart ' + this.id);
@jparbros
jparbros / application_controller.rb
Created April 12, 2012 16:12
omniture_common_params refactor #1
class ApplicationController < ActionController::Base
helper_method :omniture_common_params, :set_omniture_cookie
def omniture_common_params(omniture_data_objs)
omniture_data_arr = [omniture_data_objs].flatten.compact
# Set the omniture LOGIN
if params[:logged] || session['omn_fire_registration_success']
omniture_data_arr.insert(0, Omniture.generate_params(:login_success, params))
@jparbros
jparbros / application_controller.rb
Created April 12, 2012 16:17
omniture_common_params refactor #2
class ApplicationController < ActionController::Base
include Omniture::Helper
end