Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
class AddConstraintsToAssets < ActiveRecord::Migration
def self.up
execute "alter table #{Asset.table_name}
add constraint assets_check_kind
check (kind in (#{ Asset::KINDS.collect{|a| "'#{a}'"}.join(',') }));".to_line
end
def self.down
execute "alter table #{Asset.table_name}
drop constraint assets_check_kind;".to_line
# The test
setup do
@asset = Asset.new({:kind => 'image',
:user_rights => 3,
:everyone_rights => 1,
:description => "nice dragon",
:object => File.new(File.expand_path(File.dirname(__FILE__) + '/asset_test/dragon.svg'))
})
end
require 'rubygems'
require 'sinatra'
require 'tempfile'
class Jaxer
class << self
def json_to_png(json)
# producing tempfile
file = Tempfile.new('jaxer')
# command used to start thin
thin -s 1 -C thin/production_config.yml -R thin/config.ru start
# thin/config.ru
require 'lib/sinatra/lib/sinatra'
module HasAsset
def included base
base.class_eval do
before_create :add_asset
before_update :edit_asset
end
end
private
def edit_asset
Errno::EPIPE in Item typesController#update
Broken pipe
RAILS_ROOT: /Users/max/Sites/printio/products
Application Trace | Framework Trace | Full Trace
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:175:in `write'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:175:in `write0'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:151:in `write'
asset.put(:service_update, {
:object => Base64::encode64s(source_data),
:filename => "#{Digest::MD5.hexdigest(source_data)}.png",
:description => self.method(options[:description]).call })
module Beer
def drink
"gulp"
end
end
class Mug
include Beer
end
module Paperclipful
module UploadedFileExtensions
def to_xml(options = {})
options.reverse_merge! :indent => 2, :root => self.class.to_s.split('::').last.underscore
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent], :root => options[:root])
xml.instruct! unless options[:skip_instruct]
self.rewind
xml.tag!(options[:root], :type => :attachment) do
xml.original_path self.original_path
{"commit"=>"Create", "action"=>"create", "authenticity_token"=>"xIhGb/nKQfrrKzaJ/J2iQOrupN+81AfreutXOdIoNqY=", "controller"=>"prototypes", "prototype"=>{"title"=>"", "surface_views_attributes"=>{"new_1"=>{"description"=>"asdf", "picture"=>#<File:/tmp/RackMultipart.83249.5>}, "new_2"=>{"picture"=>#<File:/tmp/RackMultipart.83249.6>}, "new_3"=>{"picture"=>nil}}, "item_view_attributes"=>{"picture"=>nil}}}