This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$("#new_comment").submitAndUpdateCollection("#comments") | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mime::Type.register "text/html-partial", :partial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code | |
$("button").single_double_click(function () { | |
alert("Try double-clicking me!") | |
}, function () { | |
alert("Double click detected, I'm hiding") | |
$(this).hide() | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
OlderNewer