I''m trying to figure out how attachments are supposed to work with MIME
type-based responses. What makes attachments special is that in many
cases they are allowed to be arbitrary files. It would be too
restrictive to require that all possible types are registered
(Mime::Type.register).
Let''s say for GET requests on an attachment resource I want to return
metadata if the requested format is XML or JSON. Otherwise I want to
return the attachment itself.
class AttachmentsController < ApplicationController
respond_to :xml, :json
respond_to :all, :only => :show
def show
@attachment = ...
respond_with(@attachment) do
format.any { send_file @attachment.path }
end
end
end
This doesn''t work, because #any really means any, including :xml and
:json. This doesn''t work as intended, either
respond_with(@attachment) do
format.xml
format.json
format.any { send_file @attachment.path }
end
It has to be
respond_with(@attachment) do
format.xml {}
format.json {}
format.any { send_file @attachment.path }
end
But that is not the kind of code I''d like to write. I''d rather
write
respond_with(@attachment) do
format.default { send_file @attachment.path }
end
With the intended meaning that the default block is only used if
respond_to :all is active for the action and there is no more specific
explicit or implicit response for the format.
Did I miss how to do this with the existing responder code? Are there
serious reasons why it should not be done anyway?
Michael
--
Michael Schuerig
mailto:michael@schuerig.de
http://www.schuerig.de/michael/
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.