Newbie question: undefined method 'number_with_delimiter'(probably configuration problem)

167 views
Skip to first unread message

lobatt

unread,
Sep 8, 2009, 11:41:31 PM9/8/09
to Ruby on Rails: Talk
Hi all:
i am using gem to insall rails 2.3.3 and using $rails myapp to
generate my application, but strangely i can't use the number_helper
below is my env:
export RUBY_HOME=$HOME/ruby
export GEM_HOME=$HOME/gems
export RUBYLIB=$RUBY_HOME/lib:$RUBY_HOME/lib/ruby:$RUBY_HOME/lib/
site_ruby/1.8
export PATH=$HOME/gems/bin:$HOME/ruby/bin:

and:
$ locate number_helper.rb
/home/lobatt/gems/gems/actionpack-2.3.3/lib/action_view/helpers/
number_helper.rb

and i didn't modify the file under config dir except database.yml.
Isn't actionpack included in rails projects by default? how can i get
number_with_delimiter() work?

Thanks in advance.

Frederick Cheung

unread,
Sep 9, 2009, 3:36:33 AM9/9/09
to Ruby on Rails: Talk


On Sep 9, 4:41 am, lobatt <lob...@gmail.com> wrote:
> Hi all:
>        i am using gem to insall rails 2.3.3 and using $rails myapp to
> generate my application, but strangely i can't use the number_helper
>       below is my env:

Where are you calling it from ?

Fred

lobatt

unread,
Sep 9, 2009, 3:46:51 AM9/9/09
to Ruby on Rails: Talk
Fred:
Thanks for your reply, i call it from my controller, like this:
class Visitor::UserAgentStatsController < ApplicationController
def index
VisitorUserAgentStats.find(:all)
number_with_delimiter(record.user_agent)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @graph}
end
end

I wonder how can i make number_with_delimtier availabe to my code?
while i am using ApplicationController without any require or inlucde
directive...
On Sep 9, 3:36 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:

lobatt

unread,
Sep 9, 2009, 4:37:55 AM9/9/09
to Ruby on Rails: Talk
sorry, the source code should be like this:
class Visitor::UserAgentStatsController < ApplicationController
def index
@graph = Array.new
@stats = VisitorUserAgentStats.find(:all)
@stats.each do |record|
@graph.push(number_with_delimiter(record.user_agent))
end
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @graph}
end
end

Frederick Cheung

unread,
Sep 9, 2009, 4:54:49 AM9/9/09
to Ruby on Rails: Talk
On Sep 9, 8:46 am, lobatt <lob...@gmail.com> wrote:
>
> I wonder how can i make number_with_delimtier availabe to my code?
> while i am using ApplicationController without any require or inlucde
> directive...

helpers are available to views only (hence the name view helpers) (at
least not unless you start playing some games which you seem to say
you don't want to do see http://snippets.dzone.com/posts/show/1799 for
example)

Fred

lobatt

unread,
Sep 9, 2009, 6:34:39 AM9/9/09
to Ruby on Rails: Talk
Thanks Fred, it is a great help!
surely i won't apply that hack, so i just used str.gsub!(/(\d)(?=(\d\d
\d)+(?!\d))/, "\\1,")

On Sep 9, 4:54 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages