Skip to content
Newer
Older
100644 482 lines (451 sloc) 16 KB
1c16649 @dhh Added better support for using the same actions to output for differe…
dhh authored Mar 11, 2006
1 module ActionController #:nodoc:
2 module MimeResponds #:nodoc:
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
3 extend ActiveSupport::Concern
4
5 included do
6 class_inheritable_reader :mimes_for_respond_to
fa0cf66 @josevalim Add a couple more tests to respond_with.
josevalim authored Jul 29, 2009
7 clear_respond_to
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
8 end
9
10 module ClassMethods
11 # Defines mimes that are rendered by default when invoking respond_with.
12 #
13 # Examples:
14 #
15 # respond_to :html, :xml, :json
16 #
17 # All actions on your controller will respond to :html, :xml and :json.
18 #
19 # But if you want to specify it based on your actions, you can use only and
20 # except:
21 #
22 # respond_to :html
23 # respond_to :xml, :json, :except => [ :edit ]
24 #
25 # The definition above explicits that all actions respond to :html. And all
26 # actions except :edit respond to :xml and :json.
27 #
28 # You can specify also only parameters:
29 #
30 # respond_to :rjs, :only => :create
31 #
32 def respond_to(*mimes)
33 options = mimes.extract_options!
34
35 only_actions = Array(options.delete(:only))
36 except_actions = Array(options.delete(:except))
37
38 mimes.each do |mime|
39 mime = mime.to_sym
fa0cf66 @josevalim Add a couple more tests to respond_with.
josevalim authored Jul 29, 2009
40 mimes_for_respond_to[mime] = {}
41 mimes_for_respond_to[mime][:only] = only_actions unless only_actions.empty?
42 mimes_for_respond_to[mime][:except] = except_actions unless except_actions.empty?
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
43 end
44 end
45
46 # Clear all mimes in respond_to.
47 #
fa0cf66 @josevalim Add a couple more tests to respond_with.
josevalim authored Jul 29, 2009
48 def clear_respond_to
49 write_inheritable_attribute(:mimes_for_respond_to, ActiveSupport::OrderedHash.new)
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
50 end
51 end
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
52
01f032f Added responds_to to new base.
Yehuda Katz + Carl Lerche authored May 20, 2009
53 # Without web-service support, an action which collects the data for displaying a list of people
54 # might look something like this:
55 #
56 # def index
57 # @people = Person.find(:all)
58 # end
59 #
60 # Here's the same action, with web-service support baked in:
61 #
62 # def index
63 # @people = Person.find(:all)
64 #
65 # respond_to do |format|
66 # format.html
67 # format.xml { render :xml => @people.to_xml }
68 # end
69 # end
70 #
71 # What that says is, "if the client wants HTML in response to this action, just respond as we
72 # would have before, but if the client wants XML, return them the list of people in XML format."
73 # (Rails determines the desired response format from the HTTP Accept header submitted by the client.)
74 #
75 # Supposing you have an action that adds a new person, optionally creating their company
76 # (by name) if it does not already exist, without web-services, it might look like this:
77 #
78 # def create
79 # @company = Company.find_or_create_by_name(params[:company][:name])
80 # @person = @company.people.create(params[:person])
81 #
82 # redirect_to(person_list_url)
83 # end
84 #
85 # Here's the same action, with web-service support baked in:
86 #
87 # def create
88 # company = params[:person].delete(:company)
89 # @company = Company.find_or_create_by_name(company[:name])
90 # @person = @company.people.create(params[:person])
91 #
92 # respond_to do |format|
93 # format.html { redirect_to(person_list_url) }
94 # format.js
95 # format.xml { render :xml => @person.to_xml(:include => @company) }
96 # end
97 # end
98 #
99 # If the client wants HTML, we just redirect them back to the person list. If they want Javascript
100 # (format.js), then it is an RJS request and we render the RJS template associated with this action.
101 # Lastly, if the client wants XML, we render the created person as XML, but with a twist: we also
102 # include the person's company in the rendered XML, so you get something like this:
103 #
104 # <person>
105 # <id>...</id>
106 # ...
107 # <company>
108 # <id>...</id>
109 # <name>...</name>
110 # ...
111 # </company>
112 # </person>
113 #
114 # Note, however, the extra bit at the top of that action:
115 #
116 # company = params[:person].delete(:company)
117 # @company = Company.find_or_create_by_name(company[:name])
118 #
119 # This is because the incoming XML document (if a web-service request is in process) can only contain a
120 # single root-node. So, we have to rearrange things so that the request looks like this (url-encoded):
121 #
122 # person[name]=...&person[company][name]=...&...
123 #
124 # And, like this (xml-encoded):
125 #
126 # <person>
127 # <name>...</name>
128 # <company>
129 # <name>...</name>
130 # </company>
131 # </person>
132 #
133 # In other words, we make the request so that it operates on a single entity's person. Then, in the action,
134 # we extract the company data from the request, find or create the company, and then create the new person
135 # with the remaining data.
136 #
137 # Note that you can define your own XML parameter parser which would allow you to describe multiple entities
138 # in a single request (i.e., by wrapping them all in a single root node), but if you just go with the flow
139 # and accept Rails' defaults, life will be much easier.
140 #
141 # If you need to use a MIME type which isn't supported by default, you can register your own handlers in
142 # environment.rb as follows.
143 #
144 # Mime::Type.register "image/jpg", :jpg
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
145 #
146 # Respond to also allows you to specify a common block for different formats by using any:
147 #
148 # def index
149 # @people = Person.find(:all)
150 #
151 # respond_to do |format|
152 # format.html
153 # format.any(:xml, :json) { render request.format.to_sym => @people }
154 # end
155 # end
156 #
157 # In the example above, if the format is xml, it will render:
158 #
159 # render :xml => @people
160 #
161 # Or if the format is json:
162 #
163 # render :json => @people
164 #
165 # Since this is a common pattern, you can use the class method respond_to
166 # with the respond_with method to have the same results:
167 #
168 # class PeopleController < ApplicationController
169 # respond_to :html, :xml, :json
170 #
171 # def index
172 # @people = Person.find(:all)
173 # respond_with(@person)
174 # end
175 # end
176 #
177 # Be sure to check respond_with and respond_to documentation for more examples.
178 #
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
179 def respond_to(*mimes, &block)
67b2d08 @josevalim Ensure that the proper accept header value is set during tests.
josevalim authored Jul 29, 2009
180 raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
181
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
182 responder = Responder.new
183 mimes = collect_mimes_from_class_level if mimes.empty?
bbe8607 @josevalim Added tests for respond_to class method.
josevalim authored Jul 29, 2009
184 mimes.each { |mime| responder.send(mime) }
fa0cf66 @josevalim Add a couple more tests to respond_with.
josevalim authored Jul 29, 2009
185 block.call(responder) if block_given?
7af12d0 @dhh Added synonym and custom type handling to respond_to [DHH]
dhh authored Mar 12, 2006
186
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
187 if format = request.negotiate_mime(responder.order)
7a4a679 @josevalim Remove any resource logic from respond_to.
josevalim authored Jul 30, 2009
188 self.formats = [format.to_sym]
189
190 if response = responder.response_for(format)
191 response.call
192 else
193 default_render
194 end
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
195 else
196 head :not_acceptable
197 end
198 end
672941d @jeremy Introduce a default respond_to block for custom types. Closes #8174.
jeremy authored May 26, 2007
199
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
200 # respond_with allows you to respond an action with a given resource. It
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
201 # requires that you set your class with a respond_to method with the
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
202 # formats allowed:
203 #
204 # class PeopleController < ApplicationController
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
205 # respond_to :html, :xml, :json
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
206 #
207 # def index
208 # @people = Person.find(:all)
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
209 # respond_with(@people)
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
210 # end
211 # end
212 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
213 # When a request comes, for example with format :xml, three steps happen:
214 #
215 # 1) respond_with searches for a template at people/index.xml;
216 #
217 # 2) if the template is not available, it will check if the given
218 # resource responds to :to_xml.
219 #
220 # 3) if a :location option was provided, redirect to the location with
221 # redirect status if a string was given, or render an action if a
222 # symbol was given.
223 #
224 # If all steps fail, a missing template error will be raised.
225 #
226 # === Supported options
227 #
228 # [status]
229 # Sets the response status.
230 #
231 # [head]
232 # Tell respond_with to set the content type, status and location header,
233 # but do not render the object, leaving the response body empty. This
234 # option only has effect if the resource is being rendered. If a
235 # template was found, it's going to be rendered anyway.
236 #
237 # [location]
238 # Sets the location header with the given value. It accepts a string,
239 # representing the location header value, or a symbol representing an
240 # action name.
241 #
242 # === Builtin HTTP verb semantics
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
243 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
244 # respond_with holds semantics for each HTTP verb. Depending on the verb
245 # and the resource status, respond_with will automatically set the options
246 # above.
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
247 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
248 # Above we saw an example for GET requests, where actually no option is
249 # configured. A create action for POST requests, could be written as:
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
250 #
251 # def create
252 # @person = Person.new(params[:person])
253 # @person.save
254 # respond_with(@person)
255 # end
256 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
257 # respond_with will inspect the @person object and check if we have any
258 # error. If errors are empty, it will add status and location to the options
259 # hash. Then the create action in case of success, is equivalent to this:
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
260 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
261 # respond_with(@person, :status => :created, :location => @person)
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
262 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
263 # From them on, the lookup happens as described above. Let's suppose a :xml
264 # request and we don't have a people/create.xml template. But since the
265 # @person object responds to :to_xml, it will render the newly created
266 # resource and set status and location.
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
267 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
268 # However, if the request is :html, a template is not available and @person
269 # does not respond to :to_html. But since a :location options was provided,
270 # it will redirect to it.
271 #
272 # In case of failures (when the @person could not be saved and errors are
273 # not empty), respond_with can be expanded as this:
274 #
275 # respond_with(@person.errors, :status => :unprocessable_entity, :location => :new)
276 #
277 # In other words, respond_with(@person) for POST requests is expanded
278 # internally into this:
279 #
280 # def create
281 # @person = Person.new(params[:person])
282 #
283 # if @person.save
284 # respond_with(@person, :status => :created, :location => @person)
285 # else
286 # respond_with(@person.errors, :status => :unprocessable_entity, :location => :new)
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
287 # end
288 # end
289 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
290 # For an update action for PUT requests, we would have:
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
291 #
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
292 # def update
293 # @person = Person.find(params[:id])
294 # @person.update_attributes(params[:person])
295 # respond_with(@person)
296 # end
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
297 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
298 # Which, in face of success and failure scenarios, can be expanded as:
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
299 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
300 # def update
301 # @person = Person.find(params[:id])
302 # @person.update_attributes(params[:person])
303 #
304 # if @person.save
305 # respond_with(@person, :status => :ok, :location => @person, :head => true)
306 # else
307 # respond_with(@person.errors, :status => :unprocessable_entity, :location => :edit)
308 # end
309 # end
310 #
311 # Notice that in case of success, we just need to reply :ok to the client.
312 # The option :head ensures that the object is not rendered.
313 #
314 # Finally, we have the destroy action with DELETE verb:
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
315 #
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
316 # def destroy
317 # @person = Person.find(params[:id])
318 # @person.destroy
319 # respond_with(@person)
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
320 # end
321 #
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
322 # Which is expanded as:
323 #
324 # def destroy
325 # @person = Person.find(params[:id])
326 # @person.destroy
327 # respond_with(@person, :status => :ok, :location => @person, :head => true)
328 # end
329 #
330 # In this case, since @person.destroyed? returns true, polymorphic urls will
331 # redirect to the collection url, instead of the resource url.
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
332 #
7034272 @josevalim Add destroyed? to ActiveRecord, include tests for polymorphic urls fo…
josevalim authored Aug 1, 2009
333 # === Nested resources
334 #
335 # respond_with also works with nested resources, you just need to pass them
336 # as you do in form_for and polymorphic_url. Consider the project has many
337 # tasks example. The create action for TasksController would be like:
338 #
339 # def create
340 # @project = Project.find(params[:project_id])
341 # @task = @project.comments.build(params[:task])
342 # @task.save
343 # respond_with([@project, @task])
344 # end
345 #
346 # Namespaced and singleton resources requires a symbol to be given, as in
347 # polymorphic urls. If a project has one manager with has many tasks, it
348 # should be invoked as:
349 #
350 # respond_with([@project, :manager, @task])
351 #
352 # Be sure to check polymorphic_url documentation. The only occasion you will
353 # need to give clear input to respond_with is in DELETE verbs for singleton
354 # resources. In such cases, the collection url does not exist, so you need
355 # to supply the destination url after delete:
356 #
357 # def destroy
358 # @project = Project.find(params[:project_id])
359 # @manager = @project.manager
360 # @manager.destroy
361 # respond_with([@project, @manager], :location => root_url)
362 # end
363 #
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
364 def respond_with(resource, options={}, &block)
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
365 respond_to(&block)
366 rescue ActionView::MissingTemplate => e
367 format = self.formats.first
368 resource = normalize_resource_options_by_verb(resource, options)
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
369 action = options.delete(:location) if options[:location].is_a?(Symbol)
7a4a679 @josevalim Remove any resource logic from respond_to.
josevalim authored Jul 30, 2009
370
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
371 if resource.respond_to?(:"to_#{format}")
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
372 options.delete(:head) ? head(options) : render(options.merge(format => resource))
373 elsif action
374 render :action => action
375 elsif options[:location]
376 redirect_to options[:location]
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
377 else
378 raise e
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
379 end
380 end
381
7a4a679 @josevalim Remove any resource logic from respond_to.
josevalim authored Jul 30, 2009
382 protected
383
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
384 # Change respond with behavior based on the HTTP verb.
385 #
386 def normalize_resource_options_by_verb(resource_or_array, options)
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
387 resource = resource_or_array.is_a?(Array) ? resource_or_array.last : resource_or_array
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
388
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
389 if resource.respond_to?(:errors) && !resource.errors.empty?
390 options[:status] ||= :unprocessable_entity
391 options[:location] ||= :new if request.post?
392 options[:location] ||= :edit if request.put?
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
393 return resource.errors
394 elsif !request.get?
f59984c @josevalim Add nagivational behavior to respond_with.
josevalim authored Aug 1, 2009
395 options[:location] ||= resource_or_array
396
397 if request.post?
398 options[:status] ||= :created
399 else
400 options[:status] ||= :ok
401 options[:head] = true unless options.key?(:head)
402 end
5b7e81e @josevalim Allow respond_with to deal with http verb accordingly.
josevalim authored Jul 31, 2009
403 end
404
405 return resource
406 end
407
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
408 # Collect mimes declared in the class method respond_to valid for the
409 # current action.
410 #
411 def collect_mimes_from_class_level #:nodoc:
412 action = action_name.to_sym
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
413
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
414 mimes_for_respond_to.keys.select do |mime|
415 config = mimes_for_respond_to[mime]
416
417 if config[:except]
418 !config[:except].include?(action)
419 elsif config[:only]
420 config[:only].include?(action)
421 else
422 true
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
423 end
424 end
09de34c @josevalim Added respond_with.
josevalim authored Jul 29, 2009
425 end
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
426
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
427 class Responder #:nodoc:
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
428 attr_accessor :order
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
429
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
430 def initialize
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
431 @order, @responses = [], {}
7af12d0 @dhh Added synonym and custom type handling to respond_to [DHH]
dhh authored Mar 12, 2006
432 end
6480d49 @jamis Add MimeResponds::Responder#any for managing multiple types with iden…
jamis authored Mar 15, 2006
433
434 def any(*args, &block)
011e469 @lifo Make MimeResponds::Responder#any work without explicit types. Closes #…
lifo authored Mar 7, 2008
435 if args.any?
436 args.each { |type| send(type, &block) }
437 else
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
438 custom(Mime::ALL, &block)
011e469 @lifo Make MimeResponds::Responder#any work without explicit types. Closes #…
lifo authored Mar 7, 2008
439 end
6dea52c @dhh Finish custom handling [DHH]
dhh authored Jun 2, 2006
440 end
7e280c3 @josevalim Remove Mime::ALL from Mime::SET.
josevalim authored Jul 29, 2009
441 alias :all :any
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
442
443 def custom(mime_type, &block)
444 mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s)
445
446 @order << mime_type
447 @responses[mime_type] ||= block
6dc1288 @wycats Remove method missing use in respond_to
wycats authored Dec 26, 2008
448 end
672941d @jeremy Introduce a default respond_to block for custom types. Closes #8174.
jeremy authored May 26, 2007
449
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
450 def response_for(mime)
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
451 @responses[mime] || @responses[Mime::ALL]
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
452 end
453
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
454 def self.generate_method_for_mime(mime)
455 sym = mime.is_a?(Symbol) ? mime : mime.to_sym
456 const = sym.to_s.upcase
457 class_eval <<-RUBY, __FILE__, __LINE__ + 1
458 def #{sym}(&block) # def html(&block)
459 custom(Mime::#{const}, &block) # custom(Mime::HTML, &block)
460 end # end
461 RUBY
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
462 end
463
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
464 Mime::SET.each do |mime|
465 generate_method_for_mime(mime)
466 end
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
467
6dc1288 @wycats Remove method missing use in respond_to
wycats authored Dec 26, 2008
468 def method_missing(symbol, &block)
469 mime_constant = Mime.const_get(symbol.to_s.upcase)
3f445b3 @josevalim Refactor Responder to only calculate available mime types. Those are …
josevalim authored Jul 28, 2009
470
6dc1288 @wycats Remove method missing use in respond_to
wycats authored Dec 26, 2008
471 if Mime::SET.include?(mime_constant)
3e8ba61 @josevalim Refactor even more Responder. Move mime negotiation to request and ad…
josevalim authored Jul 28, 2009
472 self.class.generate_method_for_mime(mime_constant)
6dc1288 @wycats Remove method missing use in respond_to
wycats authored Dec 26, 2008
473 send(symbol, &block)
6dea52c @dhh Finish custom handling [DHH]
dhh authored Jun 2, 2006
474 else
475 super
476 end
6480d49 @jamis Add MimeResponds::Responder#any for managing multiple types with iden…
jamis authored Mar 15, 2006
477 end
672941d @jeremy Introduce a default respond_to block for custom types. Closes #8174.
jeremy authored May 26, 2007
478
1c16649 @dhh Added better support for using the same actions to output for differe…
dhh authored Mar 11, 2006
479 end
480 end
0ee1cb2 @jeremy Ruby 1.9 compat, consistent load paths
jeremy authored Oct 2, 2007
481 end
Something went wrong with that request. Please try again.