Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
ActionController::Routing::Routes.draw do |map|
map.with_options :controller => "info" do |info|
%w[action1 action2 whatever yada1 yada2 yada3].each do |action|
info.send(action, action, :action => action)
end
info.home "/"
info.root
end
# steroids_on_steroids
class Steroids
def initialize
Steroids.new
end
end
# in config/routes.rb
map.blog "/blog", :controller => "blog"
map.blog "/blog/:id", :controller => "blog", :action => "show", :id => id
class Thing
attr_accessor :name, :age
end
class Thing < Struct.new(:name, :age)
end
module Kernel
def ensure_a
self.is_a?(Array) ? self : [self]
end
end
module AuthenticatedSystem
protected
# Returns true or false if the user is logged in.
# Preloads @current_user with the user model if they're logged in.
def logged_in?
!!current_user
end
# Accesses the current user from the session.
# Future calls avoid the database because nil is not equal to false.
Comatose.configure do |config|
config.admin_includes << :your_authentication_module
config.admin_authorization = :your_auth_before_filter_method
config.admin_get_root_page do
if current_user.role == 'troop_leader'
require 'rubygems'
require 'httparty'
class CalorieKing
include HTTParty
basic_auth '84294d7ae4454189bf2a3ebc37a0e421', ''
base_uri 'http://foodsearch1.webservices.calorieking.com/rest'
def self.search(term)
get("/search/#{term}")
end
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var $j = jQuery.noConflict();
jQuery(document).ready(function($){
var rowGuid = 0;
var $j = jQuery.noConflict();
jQuery(document).ready(function($){
$("#id_of_my_textarea").markItUp(nameOfSettings);
});
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept",