def new # @foo = Foo.new @foos = Foo.find(:all,:conditions=>["project_id = #{@project.id}"]) @foolist = @foos.map do |f| { :id => f.id, :subject => f.subject} end respond_to do |format| format.json { render :json => @foolist.to_json} end end
响应
[{"id":6,"subject":"test1-1"},{"id":7,"subject":"11221"},{"id":8,"subject":"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"}]
改善
def test_json ActiveRecord::Base.include_root_in_json = false @foos = Foo.find(:all,:conditions=>["project_id = #{@project.id}"]) respond_to do |format| format.json { render :json => @foos} end end
rails datagrid easyui,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/yuzhengdong/p/3814785.html