How do you handle bad formats in Rails 2 routing?

How to handle bad formats in routes in Rails 2.3? For example, suppose you have an action that wants to handle html or json requests, but nothing else, how do you limit it to let the user read the errors public? The following snippet shows the beginning:

respond_to do |format|
  format.html # render the default
  format.json { do something appropriate }
  format.all  ?
end

The problem is, what to put in place of "?", I tried:

  format.all :text => "That a bad format.", :status => 406

and while the status code has been set appropriately, the text will not be displayed (at least with a format like com that I get.

One possibility would be to change the route file so that only two formats are accepted, but this led to an explosion of the route. (I have 4 acceptable formats.) The idea of ​​using

map.connect '/xyz.:format', :action => ..., :controller => ..., :format => '/html|json/'

, - - xyz.comhtml. , - .

+3
1

, , , format.all .. - , :

format.all { render :file => File.join(Rails.public_path, '406.html'), :status => 406, :content_type => 'text/html' }

"406.html" " ". .

+2

All Articles