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 7578433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:53+00:00 2026-05-30T17:25:53+00:00

How to use constraints :subdomain => ‘api’,:format => :json do end and all others

  • 0

How to use

constraints :subdomain => 'api',:format => :json do
end

and all others like www,nil and generics to redirect to www or nil (domain).

No generic subdomain, just api and only format json.

constraints :subdomain => 'api',:format => :json do
   root :to => "posts#index", :defaults => { :format => :json }
   get "posts" => "posts#index", :defaults => { :format => :json }
end

How to get default json if I access from api.domain.com/posts instead of /posts.json
This is not must have feature, but is cool.
Now I need an redirect to domain if request is not json or not Found or render as json.

api.domain.com/posts

Should:
render as json, redirect to domain.com/post or show not found page.

  • 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-30T17:25:54+00:00Added an answer on May 30, 2026 at 5:25 pm

    According to the Rails Guide on Routing it should go something like this.

    constraints :subdomain => "api" do
      resources :your_resources_go_here, :defaults => { :format => :json }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following constraints, how can I use GitHub from Windows and Unix? All
What configuration is needed to use annotations from javax.validation.constraints like @Size , @NotNull ,
I would like to use tooltip in a web page with the following constraints:
http://www.grails.org/doc/latest/ref/Constraints/validator.html I have a project where I would like users to log in with
I'm trying to use route constraints in an Asp.Net MVC Application. routes.MapRoute( theRoute, MyAction/{page},
I want to use an AOP framework, but I have two constraints. Any framework
I read here some reasons to use constraints instead of triggers. But I have
We use Oracle on a project and would like to also support MySQL. How
If I know the correct format of fields, should I create check constraints for
Possible Duplicate: What to do when I want to use database constraints but only

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.