Reputation: 644
In my rails app(3.2.14) I have in application_helper.rb
methods for converting and parsing strings, integers into USD currency, like (3000 to '30.00' or '0.99' to 99 etc.). They use number_with_precision
method from number_helper.rb
- standart rails helper.
The problem is I want to bring all of them into module located /lib
folder, but I loose rails context.
So how I can solve this problem?
Upvotes: 1
Views: 81
Reputation: 20614
do you have your configuration setup to auto-load the lib directory, by default it is not autoloaded by rails
config.autoload_paths += %W(#{config.root}/lib)
then use include Module
in your lib files (as phoet explained), or use longer include syntax http://api.rubyonrails.org/classes/ActionView/Helpers.html -
include ActionView::Helpers::NumberHelper
Upvotes: 1
Reputation: 18845
You require the specific helper from actionpack like
require 'action_view/helpers/number_helper'
and use it in your code
include NumberHelper
Upvotes: 1