This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In .irbrc | |
# then when you want to play with generating urls from the console, | |
# just call make_urls and you're set. | |
def make_urls | |
self.class.class_eval do | |
include ActionController::UrlWriter | |
mattr_accessor :default_url_options | |
end | |
self.class.default_url_options = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Neater Github gem dependencies for Rails | |
module GithubGem | |
def github_gem(gem_name, opts={}) | |
lib_name = gem_name.split('-', 2)[1] | |
self.gem gem_name, {:lib => lib_name, :source => 'http://gems.github.com'}.merge(opts) | |
end | |
end | |
Rails::Initializer.run do |config| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails CMS alternatives | |
====================== | |
Active projects: | |
--------------- | |
adva-cms | |
repo: http://github.com/svenfuchs/adva_cms/ | |
site: http://adva-cms.org/ | |
Last update: 11/24/09 | |
"the cutting edge Rails CMS platform" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In my test_helper | |
def self.should_have_valid_test_data | |
klass = self.name[/^(.*)Test$/, 1].constantize | |
test "#{klass.name} should have valid fixtures" do | |
invalids = klass.all.reject{|m|m.valid?} | |
message = "Expected all #{klass.name} fixtures to be valid.\nInvalids:\n#{ | |
invalids.map{|m| [m.errors.full_messages, m]}.pretty_inspect}" | |
assert_block(message) { invalids.empty? } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
require 'activerecord' | |
#db settings | |
ActiveRecord::Base.establish_connection( | |
:adapter => '', | |
:encoding => '', | |
:database => '', | |
:username => '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Why even the simple validations for ActiveRecord must also be tested. | |
# Can you spot the error? | |
validates_numericality_of :discount, :allow_nil => false, | |
:greater_than_or_equal => 0, | |
:less_than_or_equal_to => 100, | |
:if => :published? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the pagination information from the response headers | |
// Wrap Backbone.sync to save the pagination header on the response object. | |
Backbone.sync_with_pagination = function(method, model, success, error) { | |
var success_with_pagination = function(resp, status, xhr) { | |
resp.next_page = xhr.getResponseHeader('X-Next-Page'); | |
return success(resp); | |
} | |
return Backbone.sync_without_pagination(method, model, success_with_pagination, error); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript | |
powered JS and SASS powered CSS with YUI compression all via the magic of rack. | |
This stuff will be native in Rails 3.1 and the layout of the files on the | |
filesystem will be different but this guide will get you working with it | |
while we wait for all that to finalize. | |
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's face it. Ruby's Hash#to_s output isn't very useful. | |
# Here's a draft for a better version. | |
class Hash | |
def to_s | |
keys.inject([]) do |a, key| | |
a << "#{key}: #{fetch(key)}" | |
end.join(', ') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin::Dashboards.build do | |
# Add this section in your dashboard... | |
section "Background Jobs" do | |
now = Time.now.getgm | |
ul do | |
li do | |
jobs = Delayed::Job.where('failed_at is not null').count(:id) | |
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red' | |
end |