【发布时间】:2014-02-23 12:26:46
【问题描述】:
我正在制作一个 rest api,并有几个使用 respond_to 和 respond_with 的控制器,一切正常。
class ItemController < ApiController
respond_to :json
def index
respond_with Item.all
end
end
我希望控制器返回不基于实体的 JSON
class ReportController < ApiController
def index
@mylist << {
:id => 1,
:name => "test"
}
what goes here to return @mylist as json ?
end
end
我尝试了几种不同的返回 @mylist 变体,这给了我类似的错误
nil:NilClass 的未定义方法 `
提前致谢!
【问题讨论】:
标签: ruby-on-rails rails-activerecord