On Fri, 2006-03-17 at 15:21 -0800, s.ross wrote:
Craig–
The reason you are getting the same responses from people is that they are
all doing the same thing with partials from collections and it’s working.
You haven’t said where you get your instance variable and I assumed (as I
suspect many will) that you are working with an AR derived type. If that’s
not the case, we may be barking up the wrong tree.
actually, I did provide the exact code from which I derive the instance
variable…and carried it forward for a few replies until it got in the
way and you replied to the exact message that had that code yesterday
but I will provide it again since you are claiming that I haven’t said
where the instance variable is coming from…
def fac_log_all_test
@facility_log = facility_log_run( 1, 14 )
end
def facility_log_run number, max
results = []
number.upto(max) do |idx|
facility = Facility.find( idx )
placements = Placement.find(:all,
:conditions => [ “facility_id = ?”, idx ])
results << { :facility => facility,
:placements => placements }
end
results
end
As you can see, @facility_log (my instance variable) is derived from the
method facility_log_run and is an array of hashes (facility) with
another hash inside the array of hashes (placements) and given my
understanding, this should qualify that I am working with an AR derived
type.
I also provided an excessively trimmed down version of the resultant
value of the instance variable at the moment of :render with :collection
If it is an AR derived type, you should only have an array of hashes, and if
you have associations the relationed fields will be arrays of hashes.
In a sense, yes, the ‘Facility’ model has_many :placements and it is
this relationship that comprises the internal loop or the placements has
inside the facility hash within the array that is the @facility_log
instance variable.
Please consider my recommendation of Four Days
(http://www.rubyonrails.com/media/text/Rails4Days.pdf). On about page 22, it
describes using partials to display data in a collection. It uses the old
syntax of render_collection_of_partials, but you can map that to
but once again, just like yesterday, you are telling me two things - and
I don’t dispute the validity of either of them…
1 - people are using it.
2 - look at this other example.
The issue that people are using it is something I don’t argue. But a
function that is wrapped within another function and breaks because it
is wrapped inside another function neither proves that the function
doesn’t work nor that it does work…it suggests that the function might
be fragile and possibly what is known as a bug. I am not smart enough
about these things to know that it is a bug and don’t have the toolsets
yet to figure this out.
The issue of looking at this other example is valid to a point, but I’ve
seen working examples and agree that in most instances it does work. The
instances are simplifications of model, view and controller code. Does
that mean that in more complicated multi-tiered arrays/hashes that it
will always work?
I am perfectly willing to put this to rest at this point - apparently it
depends upon the willingness of Brian H. to stay involved - as I
have stated, I have a methodology which is working and I can move
forward but it is not as the documentation says it should be and that
bothered me (and evidently bothered Dave because I gave sentiment to
that feeling with specific reference to the AWDWR book). The larger
issue that bothered me was the really scant amount of documentation to
the usage of render :partial and :collection as it does represent a
fairly sophisticated application and at the very least in my case, was
problematic but admittedly, that may be because I am not too bright.
I will quote a related thread on another list on this subject from
someone who is listed in the credits in Dave’s ‘PickAxe’ book…
“I found partials amazingly obtuse. The docs are unclear. Three or
four Rails apps later, I still keep figuring out stuff. I have a lot of
“Oh, so that’s how that’s supposed to work” moments, I think because
the code and API revolves around how one or a small number of people
just happened to have evolved the code, while observing their own
habits. So it sometimes seems that the design is not based on
well-reasoned choices to improve clarity or simplicity, but a
formalizing of the habits the developers acquired as they got used to
their own code.”
I can appreciate that few if any want to work through the issue with me
as it entirely possible if not probable that it will ultimately serve
little purpose other than to find bad code from newbie programmer at a
too large investment in time…but recognize that it may be valid for me
to believe that underlying structure that works properly in simple MVC
form can break when the application is less than simple MVC.
Craig