2014-01-07 45 views

回答

3

這是parameterize的來源。所以,你可以定義一個新的方法的最後一行parameterized_string.downcase只是改變parameterized_string

# File activesupport/lib/active_support/inflector/transliterate.rb, line 80 
def parameterize(string, sep = '-') 
    # replace accented chars with their ascii equivalents 
    parameterized_string = transliterate(string) 
    # Turn unwanted chars into the separator 
    parameterized_string.gsub!(/[^a-z0-9\-_]+/, sep) 
    unless sep.nil? || sep.empty? 
    re_sep = Regexp.escape(sep) 
    # No more than one of the separator in a row. 
    parameterized_string.gsub!(/#{re_sep}{2,}/, sep) 
    # Remove leading/trailing separator. 
    parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/, '') 
    end 
    parameterized_string.downcase 
end 
0

我不知道你要什麼,但parameterize方法的目的是使串網址安全。 Capital letters are not safe to use in URLs.

但是,如果你堅持,你可以送花兒給人做:

"AsDF".parameterize.capitalize # => "Asdf" 
相關問題