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 / 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 / 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
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
@murdoch
murdoch / gist:7204126
Created October 28, 2013 20:34
Devise: Do something if it's the first login, there are much better ways to do this, but here's a quick one
def after_sign_in_path_for(resource_or_scope)
if first_login
getting_started_path
else
super
end
end
def first_login
current_user.sign_in_count == 0
@murdoch
murdoch / gist:7205439
Created October 28, 2013 21:49
Devise allow unconfirmed access to site, but force confirmation for certain actions
Devise by default has a configuration named:
config.allow_unconfirmed_access_for
You can set it in your devise initializer and it will allow the user to access any page, any time, while still unconfirmed.
Then, for the pages you require confirmation, you can simply add a before filter:
before_filter :only_confirmed
@murdoch
murdoch / gist:7207237
Created October 29, 2013 00:28
Rspec "expect" snippets found on Stackoverflow
expect { thing.destroy }.to change(Thing, :count).from(1).to(0)
expect { thing.tax = 5 }.to change { thing.total_price }.by(5)
expect { thing.save! }.to raise_error
expect { thing.symbolize_name }.to change { thing.name }.from(String).to(Symbol)