Include picture url to xml file
I have the following which renders information from my groups in through xml, this code works well.
respond_to do |format|
   format.html # index.html.erb
        format.xml  { 
          groups_xml = @groups.to_xml(:include => [:enrolled_users, :tracks, :events]) 
          render :xml => courses_xml
        }
   end
end
In a second part I want add url picture to this xml. Currently I use the following code to get the picture url, and know I need to add it to the xml render but I don't know how
picture = Groups.find(params[:id开发者_如何学运维]).groups.logo.public_filename(:avatar)
I'm looking for an answer for 1 month and now I don't know where I can find out.
Assuming that each group has a logo that you're trying to include in the xml, you could add a method to the group model like:
class Group
  def avatar_filename
    logo.public_filename :avatar
  end
end
and then add :avatar_filename to the :include option you are already passing to to_xml, like this:
@groups.to_xml(:include => [:enrolled_users, :tracks, :events, :avatar_filename])
Is this what you're looking for?
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论