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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -