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
# 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> |
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
## 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. |
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
# 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 |
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
# 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 |
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
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] |
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
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 | |
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
# 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, |
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
## Imagine the following files: | |
# foo.css.scss | |
@import bar | |
foo { | |
@include bar | |
} |
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
class Fixnum | |
def seconds | |
self | |
end | |
def minutes | |
self * 60 | |
end | |
def hours |