How to generate plists from rails models?

那年仲夏 提交于 2019-12-10 11:47:35

问题


I'm rather new at ruby (on rails) and I can't figure this one out;
What is the best way to serialize objects to plist in rails?
I'm using the plist library from rubyforge.
And I have nested_attributes:

class Deck  
deck has_many :cards  
accepts_nested_attributes_for :cards  

class Card  
belongs_to :deck

I've tried in the deck controller to do this:

format.plist { render :plist => @deck.to_plist }

But I don't get the cards...
Similar in xml, I can do this:

format.xml  { render :xml => @deck.to_xml(:include => :cards) }

And get the desired output.
Can anyone help or point me in the right direction?


回答1:


Have you registred the mime type in your environment.rb ?

Mime::Type.register "text/plist", :plist

this could help http://blog.willj.net/2010/01/25/generating-a-plist-file-in-rails/

bye



来源:https://stackoverflow.com/questions/4733810/how-to-generate-plists-from-rails-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!