rails 3 two lines install
1 gem install i18n tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler 2 3 gem install rails --pre
1 gem install i18n tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler 2 3 gem install rails --pre
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
1 class MyModel < ActiveRecord::Base 2 default_scope :order => 'created_at desc' 3 end
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
1 validates_attachment_content_type :image, 2 :content_type => [ 3 'image/jpeg', 4 'image/pjpeg', # for progressive jpeg (IE mine-type for regular jpeg) 5 'image/png', 6 'image/x-png', # IE mine-type for PNG 7 'image/gif' 8 ]
having example in rails. from: http://blog.grayproductions.net/articles/five_activerecord_tips
1 duplicates = User.find( :all, 2 :select => "email, COUNT(email) AS duplicate_count", 3 :conditions => "email IS NOT NULL AND email != ''", 4 :group => "email HAVING duplicate_count > 1" 5 )
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 >>
1 @files = Dir.glob("public/files/*") 2 3 for file in @files 4 puts file 5 end
1 validates_format_of :email, 2 :with => /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/, 3 :message => "is invalid"