lib/responses.rb
module Responses
class Response
def to_json
JSON.pretty_generate(self)
end
end
class ErrorResponse < Response
def initialize(cause)
self[:type]="Error"
self[:casue]=cause
end
end
class DataResponse < Response
attr_accessor :data
end
end
这由控制器使用:
response=Responses::DataResponse.new
response.data=someData
render :json => response
现在我wrong number of arguments (1 for 0)
在lib/responses.rb:3:in to_json
. 为什么?没有参数传递给to_json
隐式调用的render :json
。那么我的错误在哪里?