如何从 Rails 模型生成 plist?
我对 ruby(在 Rails 上)相当陌生,我无法弄清楚这个问题;
在 Rails 中将对象序列化到 plist 的最佳方法是什么?
我正在使用 rubyforge 的 plist 库。
我有nested_attributes:
class Deck
deck has_many :cards
accepts_nested_attributes_for :cards
class Card
belongs_to :deck
我已经尝试在牌组控制器中执行此操作:
format.plist { render :plist => @deck.to_plist }
但我没有得到卡片...
与 xml 类似,我可以这样做:
format.xml { render :xml => @deck.to_xml(:include => :cards) }
并获得所需的输出。
谁能帮助或指出我正确的方向?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在您的environment.rb中注册了mime类型?
这可能会有所帮助 http://blog.willj .net/2010/01/25/generate-a-plist-file-in-rails/
再见
Have you registred the mime type in your environment.rb ?
this could help http://blog.willj.net/2010/01/25/generating-a-plist-file-in-rails/
bye