Skip to content

Instantly share code, notes, and snippets.

@psy-q
psy-q / 20110117113700_remove_fk_indices.rb
Created November 4, 2011 12:14
20110117113700_remove_fk_indices.rb
class RemoveFkIndices < ActiveRecord::Migration
# Remove old foreign key remains
def self.up
# MySQL and ActiveRecord produce problems with each other:
# http://lists.mysql.com/mysql/204151
# http://lists.mysql.com/mysql/204199
# http://bugs.mysql.com/bug.php?id=10333
# AR seems to guess the wrong foreign key name, which it can't remove.
@psy-q
psy-q / database_authentication_controller.rb
Created November 8, 2011 07:58
database_authentication_controller.rb
require 'digest/sha1'
class Authenticator::DatabaseAuthenticationController < Authenticator::AuthenticatorController
$general_layout_path = 'layouts/backend/' + $theme + '/general'
layout $general_layout_path
def login_form_path
"/leihs/authenticator/db/login"
@psy-q
psy-q / gist:1497540
Created December 19, 2011 14:54
Cannot find any binaries when installing gems on rvm. Works fine on system ruby.
======= This is on the machine that has rvm ============
rca@futsch:~/work/code/ror/leihs/vendor/bundle$ rvm --version
rvm 1.10.0 by Wayne E. Seguin ([email protected]) [https://rvm.beginrescueend.com/]
rca@futsch:~/work/code/ror/leihs/vendor/bundle$ bundle --version
Bundler version 1.0.21
rca@futsch:~/work/code/ror/leihs/vendor/bundle$ bundle exec gem list rspec
@psy-q
psy-q / gist:1497558
Created December 19, 2011 14:57
strace to show that bundle exec rspec can't find the binary
stat64("/home/rca/.rvm/gems/ruby-1.8.7-p352/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/home/rca/.rvm/gems/ruby-1.8.7-p352@global/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/home/rca/.rvm/rubies/ruby-1.8.7-p352/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/home/rca/.rvm/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/usr/local/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/usr/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/bin/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/usr/local/games/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
stat64("/usr/games/rspec", 0xbfe29220) = -1 ENOENT (No such file or directory)
class ShippingCalculators::ShippingCalculator < ActiveRecord::Base
set_table_name 'shipping_calculators'
serialize :configuration, OpenStruct
belongs_to :tax_class
def initialize
@cost = BigDecimal.new("0")
@taxes = BigDecimal.new("0")
@gross_cost = BigDecimal.new("0")
Loading development environment (Rails 3.1.1)
pry(main)> wb = ShippingCalculators::WeightBased.new
=> #<ShippingCalculators::WeightBased:0x64bcf5c>
pry(main)> wb.inspect
NoMethodError: undefined method `has_key?' for nil:NilClass
from /home/rca/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing'
pry(main)> wb.name = "foo"
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.delete
@psy-q
psy-q / gist:1851834
Created February 17, 2012 08:33
Rack::Sendfile returns the whole body instead of just writing the X-Sendfile header
# This triggers said error, but only in our Rails 3.1.3 application, not in a blank Rails 3.1.3 application!
class DownloadController < ApplicationController
def download
send_file("/tmp/test.txt")
end
@psy-q
psy-q / haml.txt
Created March 30, 2012 12:14
haml explostion
parse error on value "}" (tRCURLY)
/home/rca/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/racc/parser.rb:349:in `on_error'
/home/rca/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/racc/parser.rb:99:in `_racc_do_parse_c'
/home/rca/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/racc/parser.rb:99:in `do_parse'
/home/rca/.rvm/gems/ruby-1.9.2-p318/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:750:in `process'
/home/rca/.rvm/gems/ruby-1.9.2-p318/gems/gettext_i18n_rails-0.4.5/lib/gettext_i18n_rails/ruby_gettext_extractor.rb:55:in `run'
/home/rca/.rvm/gems/ruby-1.9.2-p318/gems/gettext_i18n_rails-0.4.5/lib/gettext_i18n_rails/ruby_gettext_extractor.rb:26:in `parse_string'
/home/rca/.rvm/gems/ruby-1.9.2-p318/gems/gettext_i18n_rails-0.4.5/lib/gettext_i18n_rails/haml_parser.rb:20:in `parse'
/home/rca/.rvm/gems/ruby-1.9.2-p318/gems/gettext-2.2.0/lib/gettext/tools/rgettext.rb:140:in `block (2 levels) in parse'
@psy-q
psy-q / gist:2635349
Created May 8, 2012 14:05
I18n.locale = --> setting this is ignored
From: /home/rca/work/code/ror/leihs/app/controllers/application_controller.rb @ line 72 ApplicationController#set_gettext_locale:
67: end
68:
69: I18n.locale = locale_symbol
70: FastGettext.locale = locale_symbol.to_s
71:
=> 72: binding.pry
73:
74: end
@psy-q
psy-q / gist:2693734
Created May 14, 2012 12:44
I18n.locale = --> setting this is ignored
From: /home/rca/work/code/ror/leihs/app/controllers/application_controller.rb @ line 65 ApplicationController#set_gettext_locale:
60: current_user.language = language # language is a protected attribute, it can't be mass-asigned via update_attributes
61: current_user.save
62: current_user.reload
63: end
64: locale_symbol = current_user.language.locale_name.to_sym
=> 65: binding.pry
66: else
67: locale_symbol = Language.default_language.locale_name.to_sym