Friday, May 6, 2011

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

@Robert, @Fred, @Max

GOT IT! You all had a piece of the puzzle.

(Robert: As an aside, you mean "you call Product.descendants()" -- not
dependencies() -- but that's a trifle.)

I realized that my reason that the Fred/Robert solution didn't work was
correct: a request passes in the string "PGEBusiness", and the
controller code does something like:

file: metered_services_controller.rb
def create
...
class_name = params["metered_service"] # e.g. "PGEBusiness"
@metered_service = Object.const_get(class_name).new( ... )
...
end

Notice there's nothing there that forces a load of MeteredService, so
the calls to require_dependency() at the bottom of metered_service.rb
aren't invoked. But I can force a load of metered_service.rb by a call
to descendants():

def create
...
MeteredService.descendants()
class_name = params["metered_service"] # e.g. "PGEBusiness"
@metered_service = Object.const_get(class_name).new( ... )
...
end

And that works. *phew* Thanks for your patience.

- ff

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate