From 7a3c754e6bff4fc5f998d6e0c71ad3d6e2f83780 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Fri, 18 Jun 2010 17:57:32 +0200 Subject: [PATCH] added documentation about :plist_filename --- README | 11 ++++++++++- lib/rails_extensions.rb | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README b/README index 67f0924..2a08a4d 100644 --- a/README +++ b/README @@ -2,7 +2,8 @@ Plistifier ========== Adds the ActiveRecord#to_plist and Array#to_plist methods similar to ActiveRecord#to_xml. -The :only, :except, :methods, and :include options are supported. +The :only, :except, :methods, and :include options are supported. Additionally you can use +the :plist_filename option to change the default name for download. It too ads the :plist option to the ActiveRecord::Base#render method. With help of that you get binary plist files which you can easy use in your iPhone. @@ -39,6 +40,14 @@ In your PostController use for example: end end + def show + @post = Post.find(params[:id]) + + respond_to do |format| + format.plist { render :plist => @post, :plist_filename => "a-testfile.plist" } + end + end + On the iPhone use for example: NSURL *url = [NSURL URLWithString:@"http://example.com/posts.plist"]; diff --git a/lib/rails_extensions.rb b/lib/rails_extensions.rb index d3a7bfc..57c6742 100644 --- a/lib/rails_extensions.rb +++ b/lib/rails_extensions.rb @@ -30,9 +30,9 @@ module ActionController unless options.nil? or options[:plist_filename].blank? if plist.is_a? Array - filename = plist.first.class.name.pluralize + filename = plist.first.class.name.pluralize + ".plist" else - filename = "#{plist.class.name}-#{plist.id}" + filename = "#{plist.class.name}-#{plist.id}.plist" end else filename = options[:plist_filename] @@ -41,7 +41,7 @@ module ActionController send_data( plist.to_plist(options), :type => Mime::PLIST, - :filename => "#{filename}.plist", + :filename => filename, :disposition => 'inline' )