Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
# note that last item is User class
a = [10, [20, 30, ["helo", "world"]], [1.2, 1.3], {:foo => :bar}, User]
puts a.to_xml
<?xml version="1.0" encoding="UTF-8"?>
<objects type="array">
<object type="integer">10</object>
<object type="array">
<object type="integer">20</object>
## I18n backends benchmarks
#
# All these benchmarks were performed using REE with the suite at
# at http://github.com/svenfuchs/i18n/tree/master/benchmark/run.rb
#
# When compared to ActiveRecord backend, Redis and Tokyo
# just cannot store procs. All other tests pass.
#
# Used rufus-tokyo (1.0.7) and redis (2.0.0) as gems and N = 10.
# How to give your devise controllers all the same layout (e.g. "authentication" below)
class ApplicationController < ActionController::Base
layout :setup_layout
protected
def setup_layout
devise_controller? ? "authentication" : "application"
end
end
# Customizing your Responder to always redirect to the collection path (index action).
class AppResponder < ActionController::Responder
protected
# Overwrite navigation_behavior to redirect to the collection_location.
def navigation_behavior(error)
if get?
raise error
elsif has_errors? && default_action
render :action => default_action
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 8794392..03c97bc 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -168,38 +168,52 @@ module Rails
def self.hidden_namespaces
@hidden_namespaces ||= begin
- orm = options[:rails][:orm]
- test = options[:rails][:test_framework]
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index ed82c6b..f7851df 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -179,11 +179,14 @@ module ActiveModel
# If +message+ is a proc, it will be called, allowing for things like <tt>Time.now</tt> to be used within an error.
def add(attribute, message = nil, options = {})
message ||= :invalid
+ options[:message] ||= message
# Rails developers have long had bad experiences with fixtures for
# several reasons, including misuse.
#
# Misuse of fixtures is characterized by having a huge number of them,
# requiring the developer to maintain a lot of data and creating dependencies
# between tests. In my experience working (and rescuing) many applications, 80%
# of fixtures are only used by 20% of tests.
#
# An example of such tests is one assuring that a given SQL query with
# GROUP BY and ORDER BY conditions returns the correct result set. As expected,
## Imagine the following files:
# foo.css.scss
@import bar
foo {
@include bar
}
class Fixnum
def seconds
self
end
def minutes
self * 60
end
def hours