开发者

Getting around ruby-units conflict with activesupport

开发者 https://www.devze.com 2023-04-05 05:51 出处:网络
I want to use the ruby-units with a rails 3 project, but it seems like it conflicts with activesupport.

I want to use the ruby-units with a rails 3 project, but it seems like it conflicts with activesupport.

It looks to me like both activesupport and ruby-units create a to() method for St开发者_运维知识库ring. For some reason, ruby-units one wins, and so whenever to() is called inside rails it throws an error. (Unit not recognized)

I want to know the best way to deal with this. I don't care about having the to() method from ruby-units, I just don't want it to interfere with rails. I'd like to avoid forking if there's another approach.

To see my problem:

Add to your gemfile

gem 'ruby-units'

Open up rails console (I'm on rails 3 with ruby 1.9.2) and try apples.to(1)

Without ruby-units:

"ap"

With:

"'apples' Unit not recognized"


The answer to this is to require the ruby-units library before the rails library in the Gemfile:

gem 'ruby-units'
gem 'rails'

Obviously you then won't be able to use .to() on strings to access the ruby-units conversion.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号