This file contains hidden or 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
# Monkey patch for CVE-2012-2660 and CVE-2012-2694 on Rails 2.3.14 | |
# put this file in your config/initializers directory | |
# comments/corrections: https://gist.github.com/2854095 | |
# Strip [nil] from parameters hash | |
# based on a pull request from @sebbacon | |
# https://github.com/rails/rails/pull/6580 | |
module ActionController | |
class Request < Rack::Request |
This file contains hidden or 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
# Ruby unexpected behavior when using .clone or .dup on a hash (or array) | |
# create a hash and freeze it so it shouldn't be modified | |
MY_HASH = { :one => { :first => 'eins', :second => 'zwei' } }.freeze | |
puts MY_HASH.inspect # {:one=>{:first=>"eins", :second=>"zwei"}} | |
new_hash = MY_HASH.dup # copy the hash, unfrozen | |
new_hash[:one][:second] = 'dos' |
This file contains hidden or 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 Project < ActiveRecord::Base | |
has_many :tasks | |
accepts_nested_attributes_for :tasks, :reject_if => :all_blank, :allow_destroy => true | |
def validate | |
# require a minimum of one task | |
undestroyed_task_count = 0 | |
tasks.each { |t| undestroyed_task_count += 1 unless t.marked_for_destruction? } |
This file contains hidden or 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
# monkey patch to allow authlogic's *_credentials cookies set the HttpOnly bit | |
# put this file in config/initializers/authlogic.rb and set the value after | |
# instantiating your session model, e.g. | |
# @user_session = UserSession.new(params[:user_session]) | |
# @user_session.httponly = true | |
module Authlogic | |
module Session | |
module Cookies | |
module Config |
This file contains hidden or 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
# file_column Shoulda macro, based off the Paperclip method given here: | |
# http://giantrobots.thoughtbot.com/2008/3/18/for-attaching-files-use-paperclip#comment--614050918 | |
# pass the extra option :magick => true to test the extra method for the columns that use RMagick | |
def self.should_have_file_column(attachment, options = {}) | |
klass = described_type | |
fields = ["#{attachment}", "#{attachment}=", "#{attachment}_temp", "#{attachment}_temp=", | |
"#{attachment}_dir", "#{attachment}_just_uploaded?", "#{attachment}_options", | |
"#{attachment}_relative_dir", "#{attachment}_relative_path"] | |
fields << "#{attachment}_magick_after_assign" if options[:magick] | |
should "have_file_column #{attachment}" do |
This file contains hidden or 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
# original slow method to find a number plus a divider (|) | |
# at the start of a line | |
def find_num(file, num) | |
found = false | |
File.read(file).each do |line| | |
if line.chomp.split('|', -1)[0] == num | |
found = true | |
break | |
end | |
end |
NewerOlder