Skip to content

Instantly share code, notes, and snippets.

@avi-flombaum
avi-flombaum / list.rb
Created July 9, 2013 17:57
A form writer to model pattern I use in Rails a lot.
class List < ActiveRecord::Base
attr_accessible :name, :items_to_add
has_many :items
# Allows me to easily build forms that do
# complex things but still plug into
# mass-assignment.
def items_to_add=(items)
items.each{|i| add_item(i)}
require 'sqlite3'
require 'debugger'
DB = SQLite3::Database.new("studentbody.db")
create_students_table_sql = <<SQL
CREATE TABLE students
(
id INTEGER PRIMARY KEY,
first_name TEXT,
@avi-flombaum
avi-flombaum / jquery.exists.js
Created November 26, 2012 14:16
jQuery.exists
// Calls function on $ if it is an existing piece of dom.
// $('foo.bar').exists(function(){$("#target").show();}) -> foo.bar will appear where foo.bar is present
// $('foo.baz').exists(function(){$("#target").show();}) -> foo.baz will not appear where foo.baz is not present
jQuery.fn.exists = function(func){if (this[0]) {if (func){func.apply(this, arguments);} else {return true;}} else {if (func){return this;} else {return false;}};};