Skip to content

Instantly share code, notes, and snippets.

View dandrews's full-sized avatar
🏠
Working from home

Dan Andrews dandrews

🏠
Working from home
View GitHub Profile

I wanted to use inline SVG in a rails app. Two steps were needed to enable this:

  1. Set content type to application/xhtml+xml. I enabled this globally by adding this to application_controller.rb

     before_filter{ response.content_type = 'application/xhtml+xml' }
    
  2. Indicate we're using XHTML in the <html> tag. I enabled this globally in application.html.erb:

@mig
mig / init.el
Created January 18, 2011 21:00
Simple Emacs 24 configuration for Rails development
;; emacs configuration
(push "/usr/local/bin" exec-path)
(add-to-list 'load-path "~/.emacs.d")
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq-default tab-width 2)
(setq-default indent-tabs-mode nil)
(setq inhibit-startup-message t)
@mmueller
mmueller / bitly.py
Created April 28, 2011 22:52
Command-line bit.ly URL generator (Python)
#!/usr/bin/env python
#
# Copyright 2009 Empeeric LTD. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@christineyen
christineyen / cron.rake
Created May 14, 2011 02:30
Heroku -> S3 Backup rake task
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
Rake::Task['heroku:backup'].invoke
end
@juggy
juggy / call_template.rb
Created May 17, 2011 19:25
Render a complete page in rails 3 without controller
# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")
@markoa
markoa / omniauth_callbacks_controller.rb
Created August 17, 2011 14:45
Saving LinkedIn OAuth data in a callback action (Rails controller, Devise, Omniauth).
# in your routes.rb:
# devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
#
# and view:
# link_to("Connect to LinkedIn", user_omniauth_authorize_path(:linked_in))
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
omniauth_hash = env["omniauth.auth"]
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@aarongustafson
aarongustafson / responsive-iframes.css
Created October 25, 2011 17:07
Responsive iFrames with jQuery
iframe {
max-width: 100%;
}
@bbwharris
bbwharris / us_state_loader.rake
Created February 22, 2012 03:56
States with Abbreviations, Rails, Ruby
namespace :states do
desc "load state names and abbreviations"
task :load => :environment do
states = {
"Alabama" => "AL",
"Alaska" => "AK",
"Arizona" => "AZ",
"Arkansas" => "AR",
"California" => "CA",
"Colorado" => "CO",
@travisp
travisp / invitations_controller.rb
Created March 9, 2012 15:56
devise_invitable with omniauthable
class InvitationsController < Devise::InvitationsController
# GET /resource/invitation/accept?invitation_token=abcdef
def edit
if params[:invitation_token] && self.resource = resource_class.to_adapter.find_first( :invitation_token => params[:invitation_token] )
session[:invitation_token] = params[:invitation_token]
render :edit
else
set_flash_message(:alert, :invitation_token_invalid)
redirect_to after_sign_out_path_for(resource_name)