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
Post a Comment