How to convert Ruby on Rails Model to a .json file? -


if have basic ruby on rails model set (like example typical blogpost application) index action like:

def index   @blogs=blog.all end 

how convert blogs .json file? know if do:

def index   @blogs=blog.all   respond_to |format|    format.html{}   format.json{render json: @blogs.to_json} end 

this give json output (what want) @ following path: /blogs.json in browser, want actual .json file (not 1 being visible in browser @ path).

how go doing this?

just replace

 format.json{render json: @blogs.to_json} 

by

format.json{send_data @blogs.to_json} 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -