Skip to content

Instantly share code, notes, and snippets.

puts "Loading regular seeds"
Dir[Rails.root.join("db/seed", "*.{yml,csv}")].each do |file|
Fixtures.create_fixtures("db/seed", File.basename(file, '.*'))
end
require 'active_record/fixtures'
puts "Loading regular seeds"
Dir[Rails.root.join("db/seed", "*.{yml,csv}")].each do |file|
Fixtures.create_fixtures("db/seed", File.basename(file, '.*'))
end
puts "Loading #{Rails.env} seeds"
Dir[Rails.root.join("db/seed", Rails.env, "*.{yml,csv}")].each do |file|
Fixtures.create_fixtures("db/seed/#{Rails.env}", File.basename(file, '.*'))
### USAGE ###
# MODEL=User FILE="db/seed/development/user.csv" rake export_model
task :export_model => :environment do
MODEL = ENV["MODEL"].constantize
FILE = ENV["FILE"]
objects = MODEL.find(:all)
FasterCSV.open(File.join(Rails.root, FILE), "w") do |csv|
csv << MODEL.column_names
require 'faker'
500.times do
User.create(:email => Faker::Internet.email, :name => Faker::Name.name, :password => "passw0rd", :age => (rand(60) + 1)
end
def long_method
@running = true
begin
really_long_code
ensure
@running = false
end
end
long_method # => NameError: undefined local variable or method `really_long_code' for #<Object:0x102310508>
<h1>Listing businesses</h1>
<%= add_map("map_div", @businesses, {:labels => true}) %>
<div id="map_div" style="width: 600px; height: 400px;"></div>
<table>
<tr>
<th>Address</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>
$ time ruby script/runner
Run 'script/runner -h' for help.
real 0m22.632s
user 0m7.468s
sys 0m1.933s
Rails v2.3.5 loaded via vendor/rails
def index
@query = params[:query]
@page = params.fetch(:page, 1)
if @query.nil?
@wines = Wine.paginate(:page => @page, :per_page => 9)
logger.info("Doing index, not search")
else
@search = Wine.search do
keywords(@query)
end
$(document).ready(function(){
$('a.remove-participant').live('click', function(){
console.log("Clicked remove");
$(this).parent('.participant').hide();
$(this).siblings('.destroy_participant').find('input[type="hidden"]').val(1);
return false;
});
});
@queso
queso / config.ru
Created February 6, 2011 03:30
An example config.ru file for dynamically adding CIJoe projects, just place this at the root of your folder structure
# Required so that we can set path correctly for Config, which
# is loaded statically due to a bug in cijoe
require 'cijoe'
# setup middleware
use Rack::CommonLogger
# Assume all subfolders under config.ru are git repos and collect them to spin up multiple joes
projects = Dir.glob("*/")