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
module ActiveModel | |
class Errors | |
def as_json(options=nil) | |
self | |
to_hash | |
end | |
def to_hash | |
hash = ActiveSupport::OrderedHash.new | |
each { |k, v| (hash[k] ||= []) << v } |
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 Admin::ReportsController < AdminController | |
respond_to :csv | |
def trips | |
respond_with TripReport.new | |
end | |
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
require 'rubygems' | |
require 'sinatra' | |
get "/" do | |
erb :index | |
end | |
get "/slow_network" do | |
sleep(2) | |
"Done" |
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
var Bill = Model('bill', function () { | |
this.use(Model.validations) | |
this.validatesPresenceOf(['attribute1', 'attribute2']) | |
this.validatesPresenceOf('another_attribute', { | |
'condition': function () { | |
// some condition if you need it | |
return true | |
} | |
}) |
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
var Post = Model('post', function () { | |
this.use(Model.Lunr(function () { | |
this.field('body') | |
this.field('title', { | |
'multiplier': 10 | |
}) | |
})) | |
}) |
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
$.ajaxSetup({ | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); | |
} | |
}); |
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
var cartApp = function () { | |
this.scope('/cart', function () { | |
this.post('/items', function (req) { | |
// create an item | |
}) | |
this.del('/items/:id', function (req) { | |
// delete a specific item from your cart | |
}) |
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
var app = Davis(function () { | |
this.get('/foo', function () { | |
alert('you clicked on foo!') | |
}) | |
}) |
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
var app = Davis(function () { | |
this.configure(function () { | |
this.linkSelector = 'nav a' | |
this.formSelector = 'nav form' | |
}) | |
this.get('/', function (req) { | |
showHomePage() | |
}) |
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
Davis.extend(Davis.hashRouting({ forceHashRouting: true })) | |
app = Davis(function () { | |
this.settings.handleRouteNotFound = true | |
this.get('#/foo', function () { | |
console.log('foo') | |
}) |