Skip to content

Instantly share code, notes, and snippets.

module ApplicationHelper
def body_tag_class(more_class = "")
"#{params[:controller]}_cont #{params[:action]}_action #{'logged_in' if logged_in?} #{more_class}"
end
end
#usage
%html
%body{:class => open_body_tag}
.user_controls { display:none; }
body.logged_in .user_controls { display:block; }
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
<% if page.page_type == LinkContent && page.open_link_in_new %>
<%= link_to page.name, page.link_url, :class => "nav_link", :target => '_blank' %>
<% elsif page.page_type == LinkContent %>
<%= link_to page.name, page.link_url, :class => "nav_link" %>
<% else %>
<%= link_to page.name, page_path(page), :class => "nav_link#{ ' dd_hidden_page' if page.hidden }#{ ' dd_has_sub_pages' if page.has_sub_pages }" %>
<% end %>
require 'rubygems'
require 'yajl'
require 'yajl/http_stream'
require 'uri'
require 'observer'
module Twroute
class Tweeter
include Observable
@bhauman
bhauman / just the host and scheme from a uri
Created December 2, 2009 02:08
sometimes you you ask for a hostname and you want to offer your user the option of entering the 'http://' or not
def scheme_host(url)
begin
p_uri = URI.parse(url)
p_uri.scheme = 'http'
return nil if p_uri.host == 'http'
p_uri.host = url if !p_uri.host
p_uri.select(:scheme, :host).join('://')
rescue URI::InvalidURIError
nil
rescue URI::InvalidComponentError
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%C - Century (20 in 2009)
%d - Day of the month (01..31)
%D - Date (%m/%d/%y)
%e - Day of the month, blank-padded ( 1..31)
%F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
require 'rack'
# sudo gem install tilt --source http://gemcutter.org/
require 'tilt'
# A simple Rack middleware which makes it super easy
# have a shared layout rendering system used across
# different rails applications.
#
# Examples:
#
=begin
This is quick fix for getting Rails to recognize Chrome Frame XmlHttpRequests as
Ajax Requests so that the following code will work.
respond_to do |format|
format.js { render :text => "chrome frame won't normally see this" }
end
Use:
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW