Forum: Ruby on Rails Why isn't this working???

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
flam3srock (Guest)
on 2005-12-26 02:45
This is a very straightforward problem..

-I included a mixin in lib/ (see below)
-In environment.rb, I included the require statement (require
-Defined a method in the model:

def category_list
  format_as_list #method in acts_as_tree_additions

-Called that method in the view..

I know the method is in the correct use, because it prints out a string
if I replace 'format_as_list' with a string in category_list. However,
it's not working as expected for the mixin.

Another thing is that this is a shared server, and does not need a
restart of the server (which couldn't be done either way with their port
blocking). 'require' code works for file_column without a restart, but
not this.. Am I doing something wrong?

--Thanks in advance,

(by the way.. for some reason, I login successfully, but my session
doesn't work.. so I'm posting as a guest)

## acts_as_tree_additions.rb
##credited to argv[] in #rubyonrails
module ActiveRecord::Acts::Tree::ClassMethods
  @@TreeListView_tree = nil

  def Object.format_as_list(options = {}, pid = nil, level = 0, &block)
    @@TreeListView_tree ||= self.find(:all, options)
    t =
    return t if @@TreeListView_tree.nil?
    list = @@TreeListView_tree.find_all { |e| e.parent_id == pid }.sort!
    list.each do |e|
      array_of_e = (block.nil? ? e : yield(e, level))
      t.size == 0 ? t = [array_of_e] : t << array_of_e
      t += format_as_list(options,, level + 1, &block)

  def Object.traverse_tree(options = {}, pid = nil, level = 0, &block)
    @@TreeListView_tree ||= self.find(:all, options)
    list = @@TreeListView_tree.find_all { |e| e.parent_id == pid }.sort!
    list.each do |e|
      yield(e, level)
      traverse_tree(options,, level + 1, &block)

  def Object.format_as_select_options(display_field = :name, value_field
= :id)
    format_as_list do |e, level|
      ["-" * level + " " + (e[display_field] || ""), e[value_field]]

This topic is locked and can not be replied to.