I have a ajax call, and I want to return a json response.
The controller will need to get the output of a partial, plus add some other properties to the object then serialize to json.
How can I get the output of a partial and store it to this object?
I want something like:
def my_action
my_output.html = render :partial => 'test', ....
my_output.some_prop1 = 234234
my_output.to_json
end
Then in my view I will inject the htm开发者_如何学Gol into the DOM, etc.
Just use render_to_string
in place of render
.
def my_action
output = {}
output[:html] = render_to_string :partial => 'test', ....
output[:some_prop1] = 234234
render :json => output
end
精彩评论