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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:32:53+00:00 2026-06-13T18:32:53+00:00

In Rails 3.2.8 in Ruby 1.9.3p194 when passing an array to respond_to in an

  • 0

In Rails 3.2.8 in Ruby 1.9.3p194 when passing an array to respond_to in an included block of an ActiveSupport::Concern that is included on demand in the class definition by calling an acts_as_... method in module included in a gem results in a:

respond_to causes undefined method `to_sym' for [:json, :html]:Array

and on the next request, I get:

RuntimeError (In order to use respond_with, first you need to declare the formats your controller responds to in the class level):
  actionpack (3.2.8) lib/action_controller/metal/mime_responds.rb:234:in `respond_with'

In the module code, it is just doing the equivalent of:

formats = [:json, :html]
respond_to formats

Where formats is configured elsewhere so it can be applied to all controllers that specify acts_as_....

I know it works when I do this in a class definition:

respond_to :json, :html

So, how can I call respond_to with a variable that is an array of formats?

  • 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-13T18:32:55+00:00Added an answer on June 13, 2026 at 6:32 pm

    The related parts of the respond_to method in Rails 3.2.8 are:

    def respond_to(*mimes)
      # ...
      mimes.each do |mime|
        mime = mime.to_sym
        # ...
      end
      # ...
    end
    

    Because the splat operator is used in respond_to, it is wrapping the incoming array in an array, so mimes is [[:json, :html]], and it is trying to call to_sym on the array.

    If calling respond_to with a variable containing an array, you need to use the splat (*) operator, e.g.:

    formats = [:json, :html]
    respond_to *formats
    

    That will call respond_to as if you were sending in two arguments:

    respond_to :json, :html
    

    or:

    respond_to(:json, :html)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is in Ruby 1.9.3p194, with Rails 3.2.8 app/models/owner.rb: class Owner < ActiveRecord::Base attr_accessible
My Environment Rails 3.2.1 ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] I want to change
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
This is how to convert a string to a class in Rails/Ruby: p =
I am running a Rails (3.2.3) application with Ruby 1.9.3p194 on the basic Ubuntu
bitnami@ip-10-99-67-123:~/.rvm/gems$ ruby -v ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] bitnami@ip-10-99-67-123:~/.rvm/gems$ rails -v Rails 3.2.3
Vitals: ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux] Rails 3.2.7 Devise 2.1.2 The GET /users/sign_in
ENVIRONMENT ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]; Rails 3.2.6; OSX 10.6.8 PROBLEM Even after
I am running Rails 3.2.8 and ruby 1.9.3p194. I'm trying to better understand exactly
I have just started coding with rails. I am using: Rails 3.2.8 ruby 1.9.3p194

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.