On Jan 5, 12:59 am, Fearless Fool <li...@ruby-forum.com> wrote:
subclass2.rb
> ...
>
> First, is it stylistically okay to put thermal_analysis.rb in the models
> directory, considering that it's not an ActiveRecord model? (It IS
> intimately tied to a few AR models.) If not in models, then where would
> you suggest?
/models is definitely not restricted to ActiveRecord subclasses, for
example I'd 100% put mongodb models in there. You might be able to
reasonably claim that this class does model data, the data itself is
just a layer of abstraction away. If not, then lib is where I'd put
things.
>
> Second, what's the best technique for requiring all the ThermalAnalysis
> subclasses? I could push a new value onto $LOAD_PATH from within
> thermal_analysis.rb, as in:
>
> $LOAD_PATH << File.expand_path("../thermal_analyses", __FILE__)
>
> ...but that will only get triggered when ThermalAnalysis is first
> referenced, which is usually too late. (FWIW, ThermalAnalysis is
> essentially an abstract class: only its subclasses get instantiated.)
>
Rails maps sub directories to namespaces - it will automatically look
for ThermalAnalysis::Foo in thermal_analysis/foo.rb. If you do add
something to the load path (you probably want to add it to active
support's load path so that auto require, preloading etc. work) you
could do it from an initializer ( a file in config/initializers)
Fred
> TIA.
>
> - ff
>
> --
> Posted viahttp://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.
No comments:
Post a Comment