Rails 提供了 mb_chars 來包裝以獲得正確的結果,來源:http://ihower.tw/rails2/
例如:
"中文".size # 6
"中文".mb_chars.size # 2
1.取得Gem full path:
rails c
Gem.loaded_specs['rails'].full_gem_path
2.過濾html tag in controller
string_with_html = '123'
方法一: HTML::FullSanitizer.new.sanitize(string_with_html)
方法二: include ActionView::Helpers::SanitizeHelper
strip_tags(string_with_html)
Use self.class
class Foo
def self.some_class_method
puts self
end
def some_instance_method
self.class.some_class_method
end
end
print "Class method: "
Foo.some_class_method
print "Instance method: "
Foo.new.some_instance_method
Show included_modules
a.new.included_modules
Find source location
a.method(:method_name).source_location
記錄console的 sql log Link
ActiveRecord::Base.logger = Logger.new File.open('log/development.log', 'a')
沒有留言:
張貼留言