capitalize w rails 3.2.1 #4

Closed
todhunter opened this Issue Feb 27, 2012 · 2 comments

Comments

Projects
None yet
2 participants

W rails 3.2.1 pojawia się błąd

irb(main):008:0* "Abc".camelize
NoMethodError: undefined method `upcase' for nil:NilClass
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/string_case_pl-0.1.1/lib/string_case_pl.rb:59:in `capitalize'
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:57:in `block in camelize'
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:57:in `sub'
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:57:in `camelize'
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/core_ext/string/inflections.rb:80:in `camelize'
        from (irb):8
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
        from /ror/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:41:in `'
        from script/rails:6:in `require'
        from script/rails:6:in `'

natomiast poniższe wywołanie działa poprawnie

irb(main):009:0> "abc".camelize
=> "Abc"

Na szybko obejściem jest zmiana metody

  def capitalize
    s = self.dup
    if !(s.nil?) and !(s.empty?)
      s[0] = s[0].upcase
      s[1..-1] = s[1..-1].downcase
      s
    end
  end
Owner

apohllo commented Feb 27, 2012

Ok, postaram się zrobić to w tym tygodniu. Gdy nie było zmian do przyszłego poniedziałku, to proszę o ping.

Owner

apohllo commented Feb 27, 2012

Zrobione. Gem wrzucony na rubygems (wersja 0.1.2).

apohllo closed this Feb 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment