my_key_link: 'World'
my_key: 'Hello %{link}!' link: link_to(t('my_key_link'), 'xy')
'Hello <a href="xy">World</a>!'
- Need to check if
raw
is required everytime - Translators can loose the context
#!/usr/bin/env ruby | |
ENV['RAILS_ENV'] = 'test' | |
require 'benchmark' | |
rails_loading_time = Benchmark.measure { require './config/environment' } | |
puts "Rails env loaded in #{rails_loading_time}" | |
NUM_FORKS = 2 | |
test_groups = `find ./spec -type f -iname "*foobar*"`.split("\n").in_groups(NUM_FORKS).to_a |
require 'prawn/measurement_extensions.rb' | |
class StandardBriefB < Prawn::Document | |
def initialize(*args) | |
super( | |
:page_size => 'A4', | |
:page_layout => :portrait, | |
:margin => [107.4.mm, 8.1.mm, 30.mm, 24.1.mm] | |
) | |
options = args.last.is_a?(Hash) ? args.last : {} |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_USER_AGENT} Darwin/9 | |
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-leopard.merged-1.sucatalog | |
RewriteCond %{HTTP_USER_AGENT} Darwin/10 | |
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-leopard-snowleopard.merged-1.sucatalog | |
RewriteCond %{HTTP_USER_AGENT} Darwin/11 | |
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-lion-snowleopard-leopard.merged-1.sucatalog | |
RewriteCond %{HTTP_USER_AGENT} Darwin/12 | |
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog |
# disable layout | |
page ".htaccess.apache", :layout => false | |
# rename file after build | |
after_build do | |
File.rename 'build/.htaccess.apache', 'build/.htaccess' | |
end |
This is a RESTful Rails controller, implementing all 7 RESTful actions. In my Rails apps, 9 out of 10 controllers will end up looking like this.
class PostsController < ApplicationController
load_and_authorize_resource
def create
@post.save and redirect_to(@post) or render(:new)
end
require 'nokogiri' | |
RSpec::Matchers.define :have_xpath do |*paths| | |
match do |doc| | |
!doc.xpath(*paths).empty? | |
end | |
end | |
def within *paths, &block | |
describe "within #{paths.inspect}" do |
ActiveAdmin.register Project do | |
# Don't forget to add the image attribute (here thumbnails) to permitted_params | |
controller do | |
def permitted_params | |
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list] | |
end | |
end | |
form do |f| |
-- The MIT License (MIT) | |
-- | |
-- Copyright (c) 2014 Boris Penck | |
-- | |
-- Permission is hereby granted, free of charge, to any person obtaining a copy | |
-- of this software and associated documentation files (the "Software"), to deal | |
-- in the Software without restriction, including without limitation the rights | |
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
-- copies of the Software, and to permit persons to whom the Software is | |
-- furnished to do so, subject to the following conditions: |
require 'net/http' | |
# WARNING do not use this; it works but is very limited | |
def resolve url | |
res = Net::HTTP.get_response URI(url) | |
if res.code == '301' then res['location'] | |
else url.to_s | |
end | |
end |