开发者

How do I use rails ActionView::Helpers::NumberHelper in Sinatra?

I want to use the Rails ActionView::Helpers::NumberHelper module in my Sinatra views. Specifically, I'd like to use number_to_currency though I would love to have additional Rails helpers.

If there is a more appropriate gem for Sinatra that provides number to currency, that would work too. For example, I've looked through sinatra-more, but it doesn't handle curre开发者_StackOverflowncy.

PS. I'm using Bundler.


I found that only adding:

require 'active_support'

...didn't give me all the ActiveSupport methods I was hoping for (in my case, AS' fancy time parsing methods). As such, I went with this:

Gemfile.rb

gem 'activesupport', require: 'active_support/all'

It's in my Gemfile (since I'm using Bundler).


Add require 'active_support' to the top of your sinatra application, and include the active_support gem in the bundler gem list.

Including the whole of Active Support in a Sinatra application is a little counter to the whole idea, so you could take a look at the Money gem.

require "money" (and add it to the bundler gem manifest).

Docs on Money: http://money.rubyforge.org/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜