有没有在 Rails 上转换测量单位的解决方案?
我想在 Ruby on Rails 应用程序中实现测量单位首选项。
例如,用户应该能够选择以英里或公里为单位显示距离。显然,不仅显示,还输入值。
我认为所有值都应该存储在一个全局测量系统中以简化计算。
有没有任何解决方案?或者我应该自己写?
I'd like to implement measurement unit preferences in a Ruby on Rails app.
For instance, the user should be able to select between displaying distances in miles or in kilometers. And, obviously, not only displaying, but entering values, too.
I suppose all values should be stored in one global measurement system to simplify calculations.
Are there any drop-in solutions for this? Or should I maybe write my own?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
红宝石宝石“ruby-units”可能会有所帮助:
http://ruby-units.rubyforge.org /红宝石单位/
The ruby gem "ruby-units" may help:
http://ruby-units.rubyforge.org/ruby-units/
您也许可以看看这个 gem,它可以让您执行一些单位转换。
Github 上的数量
You can maybe have a look at this gem, which let's you perform some unit conversions.
Quantity on Github
我构建了 Unitwise 来解决 Ruby 中的大多数单位转换和测量数学问题。
简单的用法如下所示:
如果您想在 Rails 模型中存储测量值,您可以执行以下操作:
I built Unitwise to solve most unit conversion and measurement math problems in Ruby.
Simple usage looks like this:
If you want store measurements in your Rails models, you could do something like this:
在 GitHub 上快速搜索发现了这个: http://github.com/collectiveidea/measurement
听起来像这样做你需要的事情(就单位之间的转换而言),但我不能说我自己使用过它。
编辑:皮埃尔的宝石看起来更坚固、更活跃。
Quick search on GitHub turned up this: http://github.com/collectiveidea/measurement
Sounds like it does what you need (as far as converting between units), but I can't say I've used it myself.
Edit: Pierre's gem looks like it's more robust and active.