2013-07-16 24 views

回答

2

見棄用警告here(從梁2):

::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:months, "Fractional months are not respected. Convert value to integer before calling #months."), caller)

現在已經,因爲Rails 3中刪除。

如果您查看原始來源,你會看到它無論如何是不能令人滿意的解決方案:

ActiveSupport::Duration.new(self * 30.days, [[:months, self]])

您可以擴展浮動類,允許這個方法:

# config/initializers/core_ext.rb 

class Float 
    def months 
    ActiveSupport::Duration.new(self * 30.days, [[:months, self]]) 
    end 
end 

然而,我會建議反對這一點。它被刪除的原因可能很難實現。

+0

謝謝,但ahving這樣:NoMethodError:未定義的方法'months_without_deprecation」 1.5:浮動。 – juanpastas

+0

@juanpastas:恐怕在'Rails 2.3'中被刪除了。比較:https://github.com/rails/rails/tree/2-3-stable/activesupport/lib/active_support/core_ext/float || https://github.com/rails/rails/tree/3-0-stable/activesupport/lib/active_support/core_ext/float。你可以通過初始化程序重新添加代碼(我會更新我的答案)。 –

相關問題