This file contains 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
<ul class="filter-list"> | |
<%- params[:filters].each do |this_filter| -%> | |
<%- parameters_minus_this = {:page => params[:page], :filters => (params[:filters] - this_filter)} -%> | |
<li><%= this_filter -%><%= link_to "[x]", parameters_minus_this -%></li> | |
<%-end-%> | |
</ul> |
This file contains 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
#!/bin/bash | |
# this script and the yuicompressor jar are in the /compressor folder distributed with the script | |
# TODO: Copy the license notes in the full version and prepend them to the minified one. | |
abspath="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" | |
dir=`dirname "$abspath"` | |
echo $dir | |
java -jar $dir/yuicompressor-2.4.2.jar --nomunge $dir/../myscript.js -o $dir/../myscript.min.js |
This file contains 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 'active_support' | |
require 'active_record' | |
TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3') | |
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE) | |
ActiveRecord::Base.establish_connection( | |
"adapter" => "sqlite3", "database" => TEST_DATABASE_FILE |
This file contains 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
# Reloads the db every time in memory. Faster (30%)!! | |
# Drop this file in spec/support | |
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") | |
ActiveRecord::Migration.verbose = false | |
ActiveRecord::Migrator.up('db/migrate') |
This file contains 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
def page_order(page, total_pages, links=9) | |
bck = ((page > links ? page-links : 1)..page).entries.reverse | |
fwd = (page..((total_pages - page > links ? page+links : total_pages))).entries | |
order = fwd.size > page ? fwd.zip(bck) : bck.zip(fwd) | |
order = order.flatten.compact.uniq[0,links].sort | |
if order[0] !=1 | |
order[1]='...' | |
order[0]=1 |
This file contains 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
class Album < ActiveRecord::Base | |
has_one :feature, :as => :featured | |
end |
This file contains 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
# Divides the hash in two, the half that meets the criteria and the one that does not. | |
yes, no = h.partition {|k,v| v>1}.map {|side| Hash[*side.flatten]} |
This file contains 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
# create models and associations from a table | |
Given(/^the following #{capture_plural_factory} and (\w*) #{capture_plural_factory} exists?:?$/) do |plural_factory, association, plural_associated_factory, table| | |
name = plural_factory.singularize | |
associated_name = plural_associated_factory.singularize | |
table.hashes.each do |hash| | |
associated_hash, hash = hash.partition {|k,v| String(k) =~ /^#{association}_.*/}.map {|h| Hash[*h.flatten]} | |
create_model(associated_name, Hash[*associated_hash.map {|k,v| [String(k).gsub(/^#{association}_/,''),v]}.flatten] ) | |
This file contains 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
Factory.define :application do |factory| | |
factory.attachment(:sample, "public/samples/sample.doc", "application/msword") | |
end |
This file contains 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
# Shorter render statement for partials | |
# From Rails 2.3 on | |
render :partial => "p", :locals => { :x => 1 } | |
# can be written as: | |
render "p", :x => 1 |
OlderNewer