Ruby1.9.3p194のRails3.2.8では、gemに含まれるモジュールrespond_to
のメソッドを呼び出すことによってクラス定義にオンデマンドで含まれるActiveSupport :: Concernに配列を渡すと、次のようになります。acts_as_...
respond_to causes undefined method `to_sym' for [:json, :html]:Array
そして次のリクエストで、私は次のようになります。
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'
モジュールコードでは、次と同等のことを行っています。
formats = [:json, :html]
respond_to formats
フォーマットが他の場所で構成されているため、を指定するすべてのコントローラーに適用できますacts_as_...
。
クラス定義でこれを行うと、それが機能することを私は知っています:
respond_to :json, :html
では、フォーマットの配列である変数を使用してrespond_toを呼び出すにはどうすればよいですか?