Created
January 22, 2011 06:12
-
-
Save briandoll/790915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeController < ApplicationController | |
# http://blog.jetthoughts.com/2010/12/22/allow-multiple-access-control-requests-for-rails/ | |
before_filter :set_access_control_headers | |
def show | |
@thing = Thing.find(params[:id]) | |
respond_to do |format| | |
format.html | |
format.json do | |
body = render_to_string(:locals => {:thing => @thing}) | |
render :json => "{ \"html\" : \"#{to_json_value(body)}\"}", :callback => params[:callback] | |
end | |
end | |
end | |
# this could either go in ApplicationController or | |
# create an instance method on String | |
def to_json_value(str) | |
str.gsub!("\"", "\\\"") | |
str.gsub!(/\n+/, " ") | |
str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment