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

  • SEARCH
  • Home
  • 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 handle situation when you have sales orders and items tables, and
How does one handle ties when ranking results in a mysql query? I've simplified
Why does IDLE handle one symbol correctly but not another? >>> e = '€'
How does one write a (Intel) F90 function that converts a string into lowercase
How does one alternate row colors in a table in django that's generated using
I have a flatiron app that now needs to be expanded to handle multipart/form-data
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
I have a screen that has a few images and one of them has
How does one handle a DateTime with a NOT NULL ? I want to
does one perform better over the other in terms of indexing/quering etc ? e.g.

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.