added documentation about :plist_filename

This commit is contained in:
Jeena Paradies 2010-06-18 17:57:32 +02:00
parent 30931f0384
commit 7a3c754e6b
2 changed files with 13 additions and 4 deletions

11
README
View file

@ -2,7 +2,8 @@ Plistifier
========== ==========
Adds the ActiveRecord#to_plist and Array#to_plist methods similar to ActiveRecord#to_xml. 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 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. 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
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: On the iPhone use for example:
NSURL *url = [NSURL URLWithString:@"http://example.com/posts.plist"]; NSURL *url = [NSURL URLWithString:@"http://example.com/posts.plist"];

View file

@ -30,9 +30,9 @@ module ActionController
unless options.nil? or options[:plist_filename].blank? unless options.nil? or options[:plist_filename].blank?
if plist.is_a? Array if plist.is_a? Array
filename = plist.first.class.name.pluralize filename = plist.first.class.name.pluralize + ".plist"
else else
filename = "#{plist.class.name}-#{plist.id}" filename = "#{plist.class.name}-#{plist.id}.plist"
end end
else else
filename = options[:plist_filename] filename = options[:plist_filename]
@ -41,7 +41,7 @@ module ActionController
send_data( send_data(
plist.to_plist(options), plist.to_plist(options),
:type => Mime::PLIST, :type => Mime::PLIST,
:filename => "#{filename}.plist", :filename => filename,
:disposition => 'inline' :disposition => 'inline'
) )