2
在Ruby 1.9.3p194中的Rails 3.2.8中,當在ActiveSupport :: Concern的包含塊中將一個數組傳遞給respond_to
時在類定義需求通過調用模塊的acts_as_...
方法包括在寶石導致:respond_to在[:json,:html]中導致未定義的方法`to_sym':Array
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一個變量,它的格式數組?