views:

31

answers:

2
+2  Q: 

RoR render method

Can I Render Json but from file? Not:

render :json => Some_object
A: 

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

http://github.com/jbr/argonaut

PeterWong
I can see, so i need to install it, and assume that i have file named succes_data.json.argonaut in views and when i call render :json => true it will be returned (the code in succes_data.json.argonaut, parsed of course)
A: 

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
kapser
That's pretty good
Isn't this only parse static data? So you are finding a way to parse pre stored data, right? Sorry for misunderstanding ^^
PeterWong
Not every time.