Skip to content

Instantly share code, notes, and snippets.

View bokmann's full-sized avatar

David Bock bokmann

View GitHub Profile
jQuery.fn.submitAndUpdateCollection = function(collection_id) {
$(this).submit(function() {
$.ajax({
type: 'post',
url: $(this).attr("action"),
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "text/html-partial")
},
data: $(this).serialize(),
success: function(partial) {
$(document).ready(function(){
$("#new_comment").submitAndUpdateCollection("#comments")
});
Mime::Type.register "text/html-partial", :partial
def create
unless @commentable.nil?
@comment = @commentable.comments.create!(params[:comment])
respond_to do |format|
format.html { redirect_to @commentable }
format.json { @commentable.to_json }
format.partial { render :partial => "comments/comment.html.erb",
:object => @comment,
:layout => false }
end
class YourTypicalWorkitem < ActiveRecord::Base
include StonePath
stonepath_workitem do
aasm_initial_state :data_entry
aasm_state :data_entry
aasm_state :data_validation
aasm_state :further_processing
@bokmann
bokmann / business_time_examples.rb
Created April 25, 2010 22:12
text for my blog entry showing how to use business_time
# require the libraries to make it all work
require 'rubygems'
require 'active_support'
require 'business_time'
# What time is it now? Of course, this will be different
# for you, so your relative answrs below will vary
# accordingly:
Time.now
@bokmann
bokmann / everytimezone.coffee
Created April 27, 2011 16:49 — forked from madrobby/everytimezone.coffee
First conversion of http://everytimezone.com/ JavaScript code to CoffeeScript
# Two things are important to note:
#
# 1) The code is fugly, because it was a JavaScript/iPad experiment.
# I know that it is ugly, so pretty please don't comment on that part.
# 2) I tried to use as many CoffeeScript features as possible,
# including but not limited to list comprehensions,
# heredocs, destructuring assignment and also the "do" operator
#
# I welcome comments about stuff that is not CoffeeScripty enough, or what I should
# write differently.
@bokmann
bokmann / README
Created April 27, 2011 16:52 — forked from ncr/README
Code
$("button").single_double_click(function () {
alert("Try double-clicking me!")
}, function () {
alert("Double click detected, I'm hiding")
$(this).hide()
})
@bokmann
bokmann / no_such_thing.rb
Created February 23, 2012 15:43
The code of the talk from my Feb 22nd Arlington Ruby talk 'There is No Such Thing as Metaprogramming'.
# This is the code from my 'There is No Such Thing as Metaprogramming' talk,
# which premiered at the Arlington, VA Ruby Users Group on Feb 22nd.
# Without the deliver and walk-through to the solution below this example
# will be missing quite an important bit of content (mainly the tracking of
# 'self' while developing the solution, but it still a useful read.
# Here is the Toddler with no metajuju. Note that the developer, as well as
# the code, is completely unuaware of the interpreter. A developer with a
# background in compiled languages would be comfortable looking at this.
@bokmann
bokmann / gist:1912278
Created February 26, 2012 02:07
notes on Mel's Peer Kit relationships...
# Mel, This is fugly, but it has the benefit of only using
# activerecord relations - here's why:
#
# Using the has_many :through technique, we need to account for the
# possibility of the 'peer' being in either of the two 'belongs_to'
# relationships in the relation. To keep ourselves mentally straight
# in this, the code refers to them as the 'left' and 'right' side.
# We need to do two queries and join them to get all the possible peers.
# There is a potentially better, but more complex solution to I'll
# outline below: