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
<% form_for setup_prototype(@prototype), :html => {:multipart => true} do |f| %> | |
<%= f.error_messages %> | |
<p> | |
<%= f.label :title %><br /> | |
<%= f.text_field :title %> | |
</p> | |
<p> | |
<%= image_tag @prototype.item_view.picture.url(:small) unless @prototype.new_record? %> | |
<%= f.label :item_view %><br /> |
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
Parameters: {"commit"=>"Create", "action"=>"create", "authenticity_token"=>"xIhGb/nKQfrrKzaJ/J2iQOrupN+81AfreutXOdIoNqY=", "controller"=>"prototypes", "prototype"=>{"title"=>"Fluffy", "surface_views_attributes"=>{"new_1"=>{"picture"=>#<File:/tmp/RackMultipart.99814.5>}, "new_2"=>{"description"=>"back", "picture"=>#<File:/tmp/RackMultipart.99814.6>}, "new_3"=>{"description"=>"", "picture"=>nil}}, "item_view_attributes"=>{"picture"=>#<File:/tmp/RackMultipart.99814.4>}}} |
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 json_to_png_file(*args) | |
returning StringIO.new(Jaxer.json_to_png(*args)) do |s| | |
s.content_type = "image/png" | |
s.original_filename = "canvas_output.png" | |
end | |
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
#!/usr/bin/env ruby | |
# | |
# usage: script/server_restarter | |
# | |
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+ | |
# is so fast when completely reloading the server, I wrote this script to listen to the | |
# given directories, and kill/restart the server when any file is changed. | |
# | |
# It's quick, simple, and it reliably reloads your application when changes are made. | |
# |
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 'w3c_validators' | |
module ShouldPassW3cValidationMacros | |
include W3CValidators | |
def should_pass_w3c_validation | |
should "pass w3c validation" do | |
tempfile = Tempfile.new('test') | |
tempfile.write(@response.body) | |
tempfile.flush |
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
# MODEL | |
class Vocabulary < ActiveRecord::Base | |
has_many :terms, :dependent => :destroy | |
accepts_nested_attributes_for :terms, | |
:allow_destroy => true, | |
:reject_if => proc { |attrs| attrs[:name].blank? } | |
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
desc "Removes all tables from the current database" | |
task(:wipe => :environment) do | |
conf = ActiveRecord::Base.configurations | |
tables = `psql #{conf[RAILS_ENV]["database"]} #{conf[RAILS_ENV]["username"]} -c "\\d" -A | grep table`.split("\n").collect{|l| l.split('|')[1]} | |
tables.each do |table| | |
if system("psql #{conf[RAILS_ENV]["database"]} #{conf[RAILS_ENV]["username"]} -c \"DROP TABLE #{table}\"") | |
puts "Dropped table #{table}" | |
else | |
puts "ERROR: Couldn't drop #{table}" | |
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
desc "Load SQL structure into database" | |
task(:load => :environment) do | |
conf = ActiveRecord::Base.configurations | |
puts "Loading sql structure..." | |
if system("psql #{conf[RAILS_ENV]["database"]} #{conf[RAILS_ENV]["username"]} < db/#{RAILS_ENV}_structure.sql") | |
puts "Done" | |
else | |
puts "Boom! Something went wrong." | |
end | |
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
#!/usr/bin/env ruby | |
# tester_elf simply autoruns a ruby test file when you save it. | |
# As dumb as it gets, but sometimes convenient. | |
# | |
# Usage: | |
# 1) Place it in your "script" dir | |
# 2) chmod +x script/tester_elf | |
# 3) script/tester_elf | |
# Stop using Ctrl/Cmd + C |
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
# On include we're grepping method baz from instance methods | |
module Foo | |
def self.included(base) | |
puts base.instance_methods.grep(/baz/).inspect | |
end | |
end | |
class Bar | |
include Foo | |
def baz; end |