parameterize

parameterize(string, sep = '-') Instance Public methods Replaces special characters in a string so that it may be used as part of a 'pretty' URL. class Person def to_param "#{id}-#{name.parameterize}" end end @person = Person.find(1) # => #<Person id: 1, name: "Donald E. Knuth"> <%= link_to(@person.name, person_path(@person)) %> # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>

ordinalize

ordinalize(number) Instance Public methods Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th. ordinalize(1) # => "1st" ordinalize(2) # => "2nd" ordinalize(1002) # => "1002nd" ordinalize(1003) # => "1003rd" ordinalize(-11) # => "-11th" ordinalize(-1021) # => "-1021st"

ordinal

ordinal(number) Instance Public methods Returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th. ordinal(1) # => "st" ordinal(2) # => "nd" ordinal(1002) # => "nd" ordinal(1003) # => "rd" ordinal(-11) # => "th" ordinal(-1021) # => "st"

inflections

inflections(locale = :en) Instance Public methods Yields a singleton instance of Inflector::Inflections so you can specify additional inflector rules. If passed an optional locale, rules for other languages can be specified. If not specified, defaults to :en. Only rules for English are provided. ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.uncountable 'rails' end

humanize

humanize(lower_case_and_underscored_word, options = {}) Instance Public methods Capitalizes the first word, turns underscores into spaces, and strips a trailing '_id' if present. Like titleize, this is meant for creating pretty output. The capitalization of the first word can be turned off by setting the optional parameter capitalize to false. By default, this parameter is true. humanize('employee_salary') # => "Employee salary" humanize('author_id')

foreign_key

foreign_key(class_name, separate_class_name_and_id_with_underscore = true) Instance Public methods Creates a foreign key name from a class name. separate_class_name_and_id_with_underscore sets whether the method should put '_' between the name and 'id'. 'Message'.foreign_key # => "message_id" 'Message'.foreign_key(false) # => "messageid" 'Admin::Post'.foreign_key # => "post_id"

demodulize

demodulize(path) Instance Public methods Removes the module part from the expression in the string. 'ActiveRecord::CoreExtensions::String::Inflections'.demodulize # => "Inflections" 'Inflections'.demodulize # => "Inflections" See also deconstantize.

deconstantize

deconstantize(path) Instance Public methods Removes the rightmost segment from the constant expression in the string. 'Net::HTTP'.deconstantize # => "Net" '::Net::HTTP'.deconstantize # => "::Net" 'String'.deconstantize # => "" '::String'.deconstantize # => "" ''.deconstantize # => "" See also demodulize.

dasherize

dasherize(underscored_word) Instance Public methods Replaces underscores with dashes in the string. 'puni_puni'.dasherize # => "puni-puni"

constantize

constantize(camel_cased_word) Instance Public methods Tries to find a constant with the name specified in the argument string. 'Module'.constantize # => Module 'Test::Unit'.constantize # => Test::Unit The name is assumed to be the one of a top-level constant, no matter whether it starts with â::â or not. No lexical context is taken into account: C = 'outside' module M C = 'inside' C # => 'inside' 'C'.constantize # => 'outside', same as ::C end