Skip to content

Instantly share code, notes, and snippets.

get '/:post_id' do
last_modification_of_post = Blog::Post[ params[:post_id], {:only => ['id', 'updated_on']} ]
last_modified( last_modification_of_post.updated_on ) if last_modification_of_post
@post = Blog::Post[ params[:post_id] ]
throw :halt, [404, erb(not_found) ] unless @post
erb :post
end
@karmi
karmi / gibberish.rake
Created August 5, 2008 13:47
Rake task to extract texts from Ruby/ERb source in your application for the Gibberish plugin dictionary
# Rake task to extract texts from Ruby/ERb source in your application
# Scans patterns like "Hello World"[:hello_world] and dumps them into RAILS_ROOT/lang/new_language.yml
# TODO: Process incrementally, ie. dump newly added strings into existing localization files
require 'fileutils'
namespace :localize do
desc "Extract all texts prepared to be translated from Ruby source"
task :extract do
count, keys, out = 0, [], "# Localization dictionary for the 'Gibberish' plugin (#{RAILS_ROOT.split('/').last})\n\n"
# IN app/controllers/application.rb
require 'uri'
before_filter :set_language
# ...
# Set language by hostname (.com => 'en', .cz => 'cz')
def set_language
def test_proper_localization_for_czech
falsify_today
hostname 'www.application.cz'
get :index
assert_tag :tag => 'h1', :content => 'Program Květen/Červen 2008'
assert_select '#topMenu a', :text => 'English'
assert_select '#headMenu strong', :text => 'Program'
assert_select '#program_item_2008-05-30 .day a', :text => 'pátek 30/05'
end
def test_should_not_list_unpublished_projects
get :index
assert_equal 13, assigns(:projects).size
assert assigns(:projects).delete_if { |p| p.published? }.empty?
end
def test_should_show_404_when_trying_to_get_not_published_project
get :show, :id => 14
assert assigns(:project)
assert_response :not_found
module ClassMethods
# Declare in ActiveRecord or ActiveResource class with localized attributes
# You must include the module "manually" in your own classes (ie. put <tt>include HasLocalizedAttributes</tt> in your class)
# See README for example
def has_localized_atributes
include InstanceMethods unless included_modules.include?(InstanceMethods)
end
end
module InstanceMethods
# Dump of table translations
# ------------------------------------------------------------
CREATE TABLE `translations` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_czech_ci default NULL,
`description` text collate utf8_czech_ci,
`lang` varchar(255) collate utf8_czech_ci default NULL,
`reference_id` int(11) default NULL,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
# artist.rb
class Artist < ActiveRecord::Base
has_many :works
has_many :compositions, :through => :works
end
# composition.rb
class Composition < ActiveRecord::Base
has_many :works
has_many :artists, :through => :works
From eb62ad214483022e5332da258f04c6480bce86cb Mon Sep 17 00:00:00 2001
From: Karel Minarik <karmi@karmi.cz>
Date: Thu, 14 Aug 2008 18:46:33 +0200
Subject: [PATCH] Added expire_fragment_by_glob() method to ActionController::Caching::Fragments
---
.../lib/action_controller/caching/fragments.rb | 14 ++++++++++++++
actionpack/test/controller/caching_test.rb | 19 +++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
@karmi
karmi / gitignore.sh
Created August 22, 2008 14:11
For noname2 :)
# vim .gitignore
.DS_Store
*/.DS_Store
log/*.log
tmp/**/*
config/database.yml
config/deploy.rb
db/*.sqlite3
doc/app/
public/uploads/*