Skip to content

Instantly share code, notes, and snippets.

@murdoch
murdoch / strip-white-space.rb
Created August 24, 2011 16:49
strip white-space from all attributes
# Just a few different methods to strip white-space from all attributes on a model.
# method 1 - code from scott moonen
# http://scottmoonen.com/2009/05/08/rails-pattern-trim-spaces-on-input/
module Trimmer
def self.included base
base.extend(ClassMethods)
end
module ClassMethods
@murdoch
murdoch / check-uri.rb
Created August 24, 2011 16:51
Check if uri exists
## just some ways to check if a url exists
# method 1 - from Simone Carletti
require "net/http"
url = URI.parse("http://www.google.com/")
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)
# method 2 - from some kid on the internet
require 'open-uri'
@murdoch
murdoch / application.css.sass
Created September 15, 2011 14:32
a gist to illustrate where to place @charset directive in case you run into the dreaded "Invalid US-ASCII character "\xE2"" whilst attempting to pre-compile Sass assets
@charset "UTF-8"
// This is a manifest file that'll automatically include all the stylesheets available in this directory
// and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
// the top of the compiled file, but it's generally better to create a new file per style scope.
//
//= require_self
// Then we'll import the compass and html5-boilerplate extensions
@import compass/utilities
@import html5/boilerplate
@murdoch
murdoch / hspm.rb
Created October 24, 2011 00:35
has secure password memo
# some notes on using has_secure_password
class User < ActiveRecord::Base
has_secure_password
attr_accessible :login_name, :password, :password_confirmation
# secure_password.rb already checks for presence of :password_digest
# so we can assume that a password is present if that validation passes
# and thus, we don't need to explicitly check for presence of password
@murdoch
murdoch / Gemfile
Created November 19, 2011 19:15
Gemfile for peerinstruction
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'haml'
gem 'devise'
gem 'json'
@murdoch
murdoch / failing-build
Created March 17, 2012 14:00
refinery on heroku
stv@home:~/Desktop/refinery$ refinerycms test_123_456 --heroku
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
@murdoch
murdoch / README.markdown
Created August 10, 2012 12:54 — forked from greypants/README.markdown
RAILS 3: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.

#About this fork

class SelfMaker
def yet_what_is_self?
self.class.class_eval do
mirror(self, "Inside class_eval of SelfMaker#yet_what_is_self?")
end
instance_eval do
mirror(self, "Inside instance_eval of SelfMaker#yet_what_is_self?")
end
@murdoch
murdoch / gist:7203932
Created October 28, 2013 20:23
Change signin path depending on url options
protected
def stored_location_for(resource)
nil
end
def after_sign_in_path_for(resource)
if condition_foo
redirect_to foo_url
elsif condition bar
@murdoch
murdoch / gist:7204104
Created October 28, 2013 20:33
Override Devise inactive signup path
# if we have confirmable module turned on
def after_inactive_sign_up_path_for(resource)
"http://google.com"
end