Welcome Guest | Login

Trouble rendering partials in an rxml file

I'm trying to render a partial in an XML response.  The line looks like this:

render(:partial => "resource", :collection => @team.resources)
This works fine in the show.rhtml file, rendering the _resource.rhtml file three times (there are three entries in the collection).  But in the show.rxml file it tries to render the _resource.rhtml file as well.  A _resource.rxml file is in place beside the _resource.rhtml file.

Is there a parameter I'm missing?  I'd expect a partial in an .rxml file to automagically look for a _partialname.rxml partial, but it's not.

2007-04-09 12:41 PM

What error are you getting? Do you think you could post your _resource.rxml code for us to see? Your controller code would also be helpful. Just don't post any sensitive information.

2007-04-09 03:16 PM

Thanks, Willc.

Controller code:
def show
 @user = User::find_by_email(session["User.id"])
 @uc = @user.user_collaborations.detect { |collaboration|
   collaboration.collaboration_id == params[:id].to_i
 }
 if @uc
   @collaboration = Collaboration.find(params[:id])
 end
 respond_to do |format|
   format.html
   format.xml
 end
end
RXML:

This works fine:
xml.instruct!
xml.collaboration_record do
 xml.timestamp(Time.now)
 xml.user(:id => @user.id) do
   xml.email(@user.email)
   xml.firstname(@user.firstname)
   xml.lastname(@user.lastname)
 end
 xml.collaboration(:id => @collaboration.id, :relationship => @uc.user_type) do
   xml.collaboration_name(@collaboration.name)
   xml.created_at @collaboration.created_at
   xml.updated_at @collaboration.updated_at
   xml.resources do
     @collaboration.resources.each do |resource|
       xml.resource(:id => resource.id) do
         xml.name resource.name
         xml.created_at resource.created_at
         xml.updated_at resource.updated_at
         xml.description resource.description
         xml.filesize resource.filesize
         xml.crc32 resource.filesize
         xml.status resource.status
       end
     end
   end
 end
end
But this does not:
xml.instruct!
xml.collaboration_record do
 xml.timestamp(Time.now)
 xml.user(:id => @user.id) do
   xml.email(@user.email)
   xml.firstname(@user.firstname)
   xml.lastname(@user.lastname)
 end
 xml.collaboration(:id => @collaboration.id, :relationship => @uc.user_type) do
   xml.collaboration_name(@collaboration.name)
   xml.created_at @collaboration.created_at
   xml.updated_at @collaboration.updated_at
   xml.resources do
     render(:partial => "resource", :collection => @collaboration.resources)
   end
 end
end
With the above (non-working) file, here's _resource.rxml:
xml.resource(:id => resource.id) do
 xml.name resource.name
 xml.created_at resource.created_at
 xml.updated_at resource.updated_at
 xml.description resource.description
 xml.filesize resource.filesize
 xml.crc32 resource.filesize
 xml.status resource.status
end
Similar code works fine when processing html requests.

As I mentioned, the logs seem to indicate that it's going straight to the .rhtml file and skipping the .rxml file entirely.

2007-04-09 03:28 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!