Skip to content

Instantly share code, notes, and snippets.

@ppworks
ppworks / Guardfile.diff
Created August 26, 2011 12:05
"Could not start Spork server for RSpec" when guard start.
diff --git a/Guardfile b/Guardfile
index 90843a8..6ffae21 100644
--- a/Guardfile
+++ b/Guardfile
@@ -1,7 +1,7 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
-guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
+guard 'spork', :wait => 60, :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
@resure
resure / key.rb
Created August 27, 2011 20:44
Key model
class Key < ActiveRecord::Base
has_secure_password
belongs_to :user
attr_accessible :title, :password, :password_confirmation, :old_password
before_validation :strip_values #, :set_password
validates :title, :length => { :within => 3..254 }
validates :user_id, :presence => true
@mimosz
mimosz / active_admin_views_pages_base.rb
Created August 31, 2011 09:50 — forked from jocubeit/active_admin_views_pages_base.rb
Override footer content in Active Admin gem
# encoding: utf-8
ActiveAdmin::Views::Pages::Base.class_eval do
private
# Renders the content for the footer
def build_footer
div :id => "footer" do
para "Copyright &copy; #{Date.today.year.to_s} #{link_to('Example.com', 'http://example.com')}. Powered by #{link_to('Active Admin', 'http://www.activeadmin.info')} #{ActiveAdmin::VERSION}".html_safe
end
end
end
@dallas
dallas / rails31init.md
Created September 11, 2011 05:22 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'my_access_key', # required
:aws_secret_access_key => 'my_secret_access_key', # required
:region => 'us-east-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = 'my_bucket_name' # required
config.fog_host = 'https://my_bucket_name.s3.amazonaws.com' # optional, defaults to nil
config.fog_public = false # optional, defaults to true
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@cblunt
cblunt / Gemfile
Created October 21, 2011 08:55
Configure Carrierwave for Amazon S3 Storage and Heroku
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
@cgriego
cgriego / evil_object.rb
Created November 30, 2011 02:52
EvilObject
class EvilObject
class << self
def const_defined?(*)
true
end
def const_get(*)
Object
end