开发者

RoR render method

开发者 https://www.devze.com 2023-01-12 03:49 出处:网络
Can I Rende开发者_如何学JAVAr Json but from file? Not: render :json => Some_object Yes you can render the data from file, It has some json formatted data in the file.

Can I Rende开发者_如何学JAVAr Json but from file? Not:

render :json => Some_object


Yes you can render the data from file, It has some json formatted data in the file.

render :json => jsonDataFromFile

//


def jsonDataFromFile
data = ""
   file = File.new("readfile.rb", "r")
   while(line = file.gets)
     data += line;
    end
data.to_json //return data
end


If you are confortable to use XML builder, then you may like this:

http://github.com/jbr/argonaut

0

精彩评论

暂无评论...
验证码 换一张
取 消