You are here: Forums Ask a Rails expert Inheritance Determination in V...
Posted in Forums : Ask a Rails expert
Authority 12
Posting Rating 0
Sign in to rate this post
|
I tried posting this on Railsforums.com, but got no answer after a week. I’m guessing that the answer is easy, I just don’t know where to look for it. Anyway, here it is: I have a view that is going to create a select box in a form, allowing the user to choose from a set of Fields. Each type of Field is determined according to an inheritance hierarchy that may be modified at some time in the future, meaning that I need the select box entries to be determined automatically. I tried using this function:[code]
The problem comes from when I call this function within the view that displays the select box. What is happening is that ObjectSpace only sees the current object associated with this view (a subclass of Field), and the Field parent, probably because Rails’ dynamic loading doesn’t see fit to load the other models within the hierarchy (which is understandable default behavior). I could manually add requires to see all the objects in question, but then I would have to update that list of requires every time a change is made to the hierarchy, and depending on where I stick the requires in the first place, I may be loading code that won’t be used in a particular situation. Since this seems like an obvious issue to come up, I’m imagining that Rails has solved this in some beautiful way, but I haven’t been able to find what it is. I have a temporary solution in place- So that’s the story. Can anyone help me out? |
Authority 62
Posting Rating 7
Sign in to rate this post
|
Just thinking outloud (I haven’t actually tried this), but what if you created a subdirectory in models to hold all these related classes (i.e. app/modes/fields/...). Then you could use a Dir.glob call on that subforlder to see what classes are defined. Assuming you stick to the standard of your filenames matching your class names, I think that should work. |
Ask a Rails expert : How to parse <pubdate> in RSS
Ask a Rails expert : Couldn't find Product without an ID
Ask a Rails expert : HTML to XML ---> get title & description
Ask a Rails expert : Accessing controller actions from scripted page?
Ask a Rails expert : seledted option for select_tag
Ask a Rails expert : Merging fields from two tables into one, including duplicates
Ask a Rails expert : saving has_many :through
Ask a Rails expert : Use Rails to develop sites for both Designer and Programmer
Ask a Rails expert : Rails+RS232
Ask a Rails expert : Is this a good way to add Admin section