This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generates a random String | |
| # 'abc'.rand(10) # => 'aacbacccbc' | |
| class String | |
| def rand(length) | |
| (1..length).inject('') {|str, i| str << self[Kernel::rand(self.length)]} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This enables the '/' resource: | |
| # map.resources :knickers, :as => '' | |
| # | |
| # GET /blabla | |
| # => KnickersController#show params = {:controller = 'knickers', :action => 'show, :id => 'blabla'} | |
| module ActionController | |
| module Resources | |
| class Resource #:nodoc: | |
| def path | |
| @path ||= path_segment.blank? ? path_prefix.to_s : "#{path_prefix}/#{path_segment}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File: config/initializers/date.rb | |
| # Parse date using Rails I18n or Ruby parse method if it failed. | |
| class Date | |
| class << self | |
| def _parse_with_i18n(str, format = :default) | |
| format ||= :default | |
| date = Date._strptime(str, I18n.translate("date.formats.#{format}")) || _parse_without_i18n(str) | |
| date[:year] += increment_year(date[:year].to_i) if date[:year] | |
| date |
NewerOlder