Adding strings to Rails JSON output -
i need output custom json in order backwards compatible existing software, written in javascript, need wrap json "parsedate(" @ beginning of it, , ");" @ end of it.
i tried doing in controller this
def index @data = data.all @products = product.all respond_to |format| format.html format.json {render :json => { :products => {:product => @data.name}}} end end
and specify in view:
app/views/products.json.erb
<%= p "parsedata(" %> <%= render :json %> <%= p "};" %> but outputs pure json skipping both "parsedata(" , ");", why? how make json printed in middle of view , append strings top , bottom?
json renderer supports callback option.
format.json { render :json => { :products => {:product => @data.name }}, :callback => 'parsedate' } you can read implementation in renderer.rb source code.
Comments
Post a Comment