Ruby on Rails Sunday, October 31, 2010

Hello,

in my controller I use following code to render json.

render :json => @product, :callback => params[:callback]

I would expect (for example) following to be rendered:

callback({"name":"Computer","price":500})

Instead, it renders:

callback([{"name":"Computer","price":500}])

Notice the square brackets which disables $.parseJSON (jQuery) from
parsing it.
Don't you know what am I doing wrong? How can I get rid of those
brackets? When I tried ActiveSupport::JSON.encode() there were no
square brackets.

Thank you very much,
Jakub Svehla

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment