def render_json(json, options={})
      callback, variable = params[:callback], params[:variable]
      response = begin
                   if callback && variable
                     "var #{variable} = #{json};\n#{callback}(#{variable});"
                   elsif variable
                     "var #{variable} = #{json};"
                   elsif callback
                     "#{callback}(#{json});"
                   else
                     json
                   end
                 end
      render({:content_type => "application/json", :text => response}.merge(options))
    end
def render_json(json, options={})
      callback, variable = params[:callback], params[:variable]
      response = begin
                   if callback && variable
                     "var #{variable} = #{json};\n#{callback}(#{variable});"
                   elsif variable
                     "var #{variable} = #{json};"
                   elsif callback
                     "#{callback}(#{json});"
                   else
                     json
                   end
                 end
      render({:content_type => "application/json", :text => response}.merge(options))
    end
thanks to http://blogs.sitepoint.com/2006/10/05/json-p-output-with-rails/