【发布时间】:2012-07-20 22:13:39
【问题描述】:
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
现在我在lib/responses.rb:3:in to_json 中收到错误wrong number of arguments (1 for 0)。
为什么?没有参数传递给to_json,它被render :json 隐式调用。那么我的错误在哪里?
【问题讨论】:
标签: ruby-on-rails ruby json