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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:40:03+00:00 2026-06-03T11:40:03+00:00

Generating a scaffold like this: rails generate scaffold User name:string email:string creates bits of

  • 0

Generating a scaffold like this:

rails generate scaffold User name:string email:string

creates bits of code that look like this in the controller class:

respond_to do |format|
  format.html # show.html.erb
  format.json { render json: @user }
end

At first I didn’t know what this meant, so I went looking and found this,
which I think adequately explains most of it. But format is supposed to end up being a Responder class. Well, there doesn’t seem to be any xml or html or json members declared in the Responder class. Where do they come from?

PS:

It seems cruel that the scaffold developer would name the block parameter “format” when it ends up being a Responder (and the format information comes from the .html, .xml, .json, or whatever) to make the code sound a bit like English but hinder understanding of what’s actually going on. In fact, Responder::respond is defined like so, which seems too coincidental:

def respond
  method = "to_#{format}"
  respond_to?(method) ? send(method) : to_format
end

But I don’t see how the format here (in “to_#{format}”) can be related to the block parameter named format. And to be clear, it’s NOT an instance variable because it’s lacking an @ sign, right?

  • 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-06-03T11:40:04+00:00Added an answer on June 3, 2026 at 11:40 am

    As the blog explains later, basically from here the Responder instance handles .html and .xml via method_missing, depending on mime types your rails app can process.
    One of the nice blogs that describe method_missing is here.
    Basically, the responder’s method_missing will get called when js and json methods are invoked. The method_missing of responder class will get the “missing method_name” (that is, :js or :json symbols) as its first parameter, which will drive its rendering logic.

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

Sidebar

Related Questions

For generating random string i written code like this But if the function is
i m generating a pdf file from the contents of email and that email
I have a brand new Rails 3.1rc4 project. After generating a scaffold, migrating and
Is there a way to generate a rails scaffold without the views, there has
SchemaTool is generating unique index for associations that are OneToOne. I believe this is
I created model objects of from generating a scaffold, but now I want to
Im generating a file to present to the user for download, but the server
When generating models from postgresql with ColdFusion Illudium Code generator the boolean values get
When generating VS2010 targets with CMake, I would like the /LTCG flag turned on
I am generating a simple form with php. The following code has been reduced

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.