Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4594948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:54:00+00:00 2026-05-21T22:54:00+00:00

How does one handle bad formats in routes in Rails 2.3? For instance suppose

  • 0

How does one handle bad formats in routes in Rails 2.3? For instance suppose that you have an action that wants to handle html or json requests but nothing else how do you restrict it while allowing user-readable errors to be promulgated? The following snippet shows a start:

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

The trouble is what to put in place of the ?, I tried:

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

and while the status code got set appropriately the text does not get rendered (at least with a format like com, which is one that I’m receiving.

One possibility would be to change the routes file so that only the two formats were accepted, but that runs into route explosion. (I have 4 acceptable formats.) The idea of using

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

sounds good but doesn’t work — it matches something like xyz.comhtml. I’m frustrated and hoping there’s something I’m missing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:54:01+00:00Added an answer on May 21, 2026 at 10:54 pm

    I might be wrong but I think for your format.all calls you can pass it a file in return.. something like this where you define the return type as well:

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

    And just put a “406.html” file in your public directory with that text “That’s a bad format.” in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one get a slider working with jQuery. HTML: <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js></script> <script
I have a POCO that is based off a normalized table. My question is
In C on FreeBSD, how does one access the CPU utilization? I am writing
Just a note : I know that in Java finally block should never throw
Say I need a new type in my application, that consists of a std::vector<int>
I'm using Prism4 and in one of my modules I'm trying to register a
I'm not very experienced in web programming, and I haven't actually coded anything in
So new to objective-c and iphone/ipad development. Trying to get my feet wet with
As I'm sure you all know Java enforces a very strict pattern for error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.