My apologies...accidentally sent before completing...
I have even tried adding a line like this to the controller''s load
method:
@test_var = "test string"
And then tried to place that value somewhere in the XML document and I
get no value. So, it seems that no local variables are being passed
between the controller and the rxml view.
Has anyone had experience with a problem like this? Or, am I missing
something obvious?
Thanks.
_____
From: Steve Johnston
Sent: Tuesday, July 26, 2005 9:06 AM
To: ''rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org''
Subject: Local variables in a XML Builder template...
I am new to both Ruby and Rails, so I''m hoping that I''m
missing
something basic here. I have a very basic controller with two methods
in it ("list" and "load"). They look like this...
class PdfController < ApplicationController
def list
@form_fields = FormField.find_all
end
def load
@form_fields = FormField.find_all
end
end
The list method causes a list.rhtml view to be rendered. That view
simply iterates across the returned array of form fields listing their
name in the resulting HTML. It works just fine. I have also created a
load.rxml view (which uses the Ruby XML Builder to generate XML output
instead of HTML) that is rendered when the load method is invoked. The
contents of the "load.rxml" file look like this...
xml.instruct! #=> <?xml version="1.0"
encoding="UTF-8"?>
xml.xfdf(:xmlns => "http://ns.adobe.com/xfdf/", :space =>
"preserve") do
xml.f(:href => "27097 - Hospital Care for the Indigent.pdf")
@form_fields.each do |field|
xml.test
end
xml.fields do
end
end
When I attempt to render this XML "view" in my browser, I get the
following error:
NoMethodError in Pdf#load
Showing /pdf/load.rxml where line #1 raised:
WARNING: You have a nil object when you probably didn''t expect it!
Odds are you
want an instance of Array instead.
Look in the callstack to see where you''re working with an object that
could be nil.
Investigate your methods and make sure the object is what you expect!
Extracted source (around line #1):
1: xml.instruct! #=> <?xml version="1.0"
encoding="UTF-8"?>
2: xml.xfdf(:xmlns => "http://ns.adobe.com/xfdf/", :space =>
"preserve")
do
3: xml.f(:href => "27097 - Hospital Care for the Indigent.pdf")
4: @form_fields.each do |field|
The way the error message is worded leads me to believe that the
@form_fields variable is not populated. However, it puzzles me that the
"list" method/view works just fine and has a very similar iteration in
it. Am I missing something obvious that my lack of Ruby skills is
keeping me from seeing?
I know the XML view itself works as I can remove the above bolded, red
lines (@form_fields iteration logic) from the view''s source and have it
render. I have even tried adding a line like this:
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails