Skip to content

Instantly share code, notes, and snippets.

View svenfuchs's full-sized avatar

Sven Fuchs svenfuchs

View GitHub Profile
def translate(locale, key, options = {})
# ...
entry = lookup(locale, key, scope) || resolve(locale, key, default, options) || raise(, key, options))
# ...
def localize(locale, object, format = :default)
raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime)
if Symbol == format
class Locale # is this a String? maybe not.
attr :language, :script, :region, :variant, :extension, :private_use
def valid?
# validate against RFC4646
def parent
# return 'en' for 'en-US' etc.
# with STI # Topic is invalid for post # Post is invalid
activerecord.errors.models.content.attributes.topic.invalid # Topic is invalid for content
activerecord.errors.models.content.invalid # Content is invalid
activerecord.errors.messages.invalid # This is invalid
Who's up to a post-railsconfeu08-coolest-quotes-tshirt-site?
Rails doesn't scale! (Oscar Wilde)
Look at all the things I'm not doing! (DHH)
Most people don't need Zulu on your website. (Josh Harvey)
t :rails (Sven Fuchs)
That is sooo "Linux"! (Jeremy Kemper)
Java is to Javascript what car is to carpet (at BoF "Xing on Rails")
No suitable for a t-shirt but still noteworthy:
# see and
# I have: "foo"
# I need: ['f', 'fo', 'foo']
require 'benchmark'
def using_split(str)
str.split(//mu).inject([]) do |arr, char|
arr << arr[-1].to_s + char.to_s
// line 272 and following - seems to work for me, at least i can drag across multiple tbodys
if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
currentRow.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
} else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
currentRow.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
describe "POST to :create" do
action { post :create, @params }
all_with :an_empty_blog
it_assigns :article
with :login_as_admin do
it "succeeds", with => :valid_article_params do
it_saves :article
it_assigns :flash :notice => :not_nil
when you read:
with [:foo, :bar], :baz
does that mean:
with(:foo AND :baz) OR with(:bar AND :baz)
or does it mean:
with(:foo AND :bar) OR with(:baz)
i.e. would the nested args array indicate a logical OR or a logical AND?
# from
require "#{File.dirname(__FILE__)}/../test_helper"
class StoriesTest < ActionController::IntegrationTest
fixtures :accounts, :ledgers, :registers, :people
def test_signup_new_person
new_session do |bob|
ActionController::Routing::Routes.draw do |map|
map.filter 'force_html'