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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:21:29+00:00 2026-05-28T03:21:29+00:00

I have a situation where I’m returning json objects to my application which are

  • 0

I have a situation where I’m returning json objects to my application which are built from YML files. Because to parse the yml file and return it as json I always have to do something like this:

format.json { render json: YAML.load(render_to_string :file => File.join(Rails.root,'app','views','home','icons.yml.erb'), :layout => false ) }

I would like to make this operation shorter, by creating a custom format that (however) result in a json, so I don’t want to create a new mime type.

My idea is to write:

format.myformat

Which will automatically search for myaction.myformat.erb inside views/mycontroller directory, and will automatically parse the yaml file returning it as a json object.

Is this possible? If yes, how can I eventually do this?

Edit 1:
I found an important suggestion in config/mime_types.rb:

Mime::Type.register_alias "text/html", :iphone

So I can alias a mime type, now the biggest problem is: how to define the default render action for a given format, like format.html does?

If I write

format.html

current_action.html.erb will be automatically rendered, how can I choose the correct method to render a custom format?

Edit 2:

I managed to create this code (inside a controller, through some helper methods I built):

  def icons
    respond_to do |format|
      format.extjson { render_to_extjson }
    end
  end

Is possible to make rails understand that if I write:

  def icons
    respond_to do |format|
      format.extjson
    end
  end

it has to do:

format.extjson { render_to_extjson }

by default?

  • 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-28T03:21:29+00:00Added an answer on May 28, 2026 at 3:21 am

    This is not doable at the moment, I read a lot of rails sources and there isn’t a way to access that method, so isn’t possible to customize it.

    I’ll write a rails plugin to support this and eventually I’ll post it here, but for sure the answer actually is: this can’t be done.

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

Sidebar

Related Questions

I have situation in which I read a record from a database. And if
I have a situation where another developer is including source files from a project
I have situation where I want to extract multiple values from multiple source objects
I have a situation in which I need to extract Data Annotations information from
I have situation in which i'm compelled to retrieve 30,000 records each to 2
i have situation in which i have some library projects, say DataProcessors,Lib2 , included
I have a situation where I could really benefit from having system like memcached,
I have unpleasant situation with testing in-app purchase in my Mac OS Application: I
I have the situation where i use GIS software which stores the information about
I have situation, where I want to read configuration file only one time, when

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.