Skip to content

Instantly share code, notes, and snippets.

@jigfox
Created February 7, 2010 22:19
Show Gist options
  • Save jigfox/297726 to your computer and use it in GitHub Desktop.
Save jigfox/297726 to your computer and use it in GitHub Desktop.
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.timestamps
end
Post.create_translation_table! :title => :string, :text => :text
end
def self.down
drop_table :posts
Post.drop_translation_table!
end
end
class Post < ActiveRecord::Base
internationalize :title, :text
end
irb(main):001:0> P = Post.new
=> #<Post id: nil, created_at: nil, updated_at: nil>
irb(main):002:0> p.title
NoMethodError: undefined method `title' for nil:NilClass
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/whiny_nil.rb:49:in `method_missing'
from (irb):2
irb(main):003:0> p.title = "test"
NoMethodError: undefined method `title=' for nil:NilClass
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/whiny_nil.rb:49:in `method_missing'
from (irb):3
irb(main):004:0> p.translated_attributes
=> {:text=>nil, :title=>nil}
irb(main):005:0> p.translations
=> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment