Send this to a friend
rails 2.3.4 doen’t have i18n support in labels
http://lawrencesong.net/2009/04/i18n-label-in-rails-monkey-patch/
1 module ActionView
2 module Helpers
3 class InstanceTag
4 def to_label_tag_with_i18n(text = nil, options = {})
5 text ||= object.class.human_attribute_name(method_name) if object.class.respond_to?(:human_attribute_name)
6
7 to_label_tag_without_i18n(text, options)
8 end
9
10 alias_method_chain :to_label_tag, :i18n
11 end
12 end
13 end
module ActionView
module Helpers
class InstanceTag
def to_label_tag_with_i18n(text = nil, options = {})
text ||= object.class.human_attribute_name(method_name) if object.class.respond_to?(:human_attribute_name)
to_label_tag_without_i18n(text, options)
end
alias_method_chain :to_label_tag, :i18n
end
end
end
Send this to a friend
run this task
1 rake paperclip:refresh class=MyClass
rake paperclip:refresh class=MyClass
Send this to a friend
1 class MyModel < ActiveRecord::Base
2 default_scope :order => 'created_at desc'
3 end
class MyModel < ActiveRecord::Base
default_scope :order => 'created_at desc'
end
Send this to a friend
1 class User < ActiveRecord::Base
2
3 HUMANIZED_ATTRIBUTES = {
4 :email => "E-mail address"
5 }
6
7 def self.human_attribute_name(attr)
8 HUMANIZED_ATTRIBUTES[attr.to_sym] || super
9 end
10
11 end
class User < ActiveRecord::Base
HUMANIZED_ATTRIBUTES = {
:email => "E-mail address"
}
def self.human_attribute_name(attr)
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end
end
Send this to a friend
1 validates_attachment_content_type :image,
2 :content_type => [
3 'image/jpeg',
4 'image/pjpeg',
5 'image/png',
6 'image/x-png',
7 'image/gif'
8 ]
validates_attachment_content_type :image,
:content_type => [
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'image/gif'
]
Send this to a friend
from: http://www.ruby-doc.org/core/classes/String.html#M000795
1 >> "abb".succ
2 => "abc"
3 >> "1".succ
4 => "2"
5 >> "1999zzz".succ
6 => "2000aaa"
7 >>
>> "abb".succ
=> "abc"
>> "1".succ
=> "2"
>> "1999zzz".succ
=> "2000aaa"
>>
Send this to a friend
to install:
gem install cldwalker-hirb —source http://gems.github.com
1 >> require 'hirb'
2 => []
3 >> Hirb.enable
4 => nil
5 >> Exam.find(:all, :limit => 5)
6 +----+----------+----------+----------+----------+---------+----------+------+
7 | id | title | exam | creat... | updat... | user_id | categ... | hits |
8 +----+----------+----------+----------+----------+---------+----------+------+
9 | 1 | Simul... | Simul... | 2009-... | 2009-... | 1 | 1 | 152 |
10 | 2 | Simul... | Simul... | 2009-... | 2009-... | 1 | 1 | 143 |
11 | 3 | Espec... | Espec... | 2009-... | 2009-... | 1 | 1 | 1089 |
12 | 4 | Espec... | Espec... | 2009-... | 2009-... | 1 | 1 | 80 |
13 | 5 | Espec... | Espec... | 2009-... | 2009-... | 1 | 1 | 40 |
14 +----+----------+----------+----------+----------+---------+----------+------+
15 5 rows in set
16 >>
>> require 'hirb'
=> []
>> Hirb.enable
=> nil
>> Exam.find(:all, :limit => 5)
+----+----------+----------+----------+----------+---------+----------+------+
| id | title | exam | creat... | updat... | user_id | categ... | hits |
+----+----------+----------+----------+----------+---------+----------+------+
| 1 | Simul... | Simul... | 2009-... | 2009-... | 1 | 1 | 152 |
| 2 | Simul... | Simul... | 2009-... | 2009-... | 1 | 1 | 143 |
| 3 | Espec... | Espec... | 2009-... | 2009-... | 1 | 1 | 1089 |
| 4 | Espec... | Espec... | 2009-... | 2009-... | 1 | 1 | 80 |
| 5 | Espec... | Espec... | 2009-... | 2009-... | 1 | 1 | 40 |
+----+----------+----------+----------+----------+---------+----------+------+
5 rows in set
>>
Send this to a friend
1 @files = Dir.glob("public/files/*")
2
3 for file in @files
4 puts file
5 end
@files = Dir.glob("public/files/*")
for file in @files
puts file
end
Send this to a friend
install:
sudo gem install google_translate
1 require 'rubygems'
2 require 'google_translate'
3
4 tr = Google::Translate.new
5
6
7 tr.translate :from => "en", :to => "es", :text => "Hello, World!"
8 => Hola, Mundo!
require 'rubygems'
require 'google_translate'
tr = Google::Translate.new
tr.translate :from => "en", :to => "es", :text => "Hello, World!"
=> Hola, Mundo!