How could I render to a string a JSON representation of a JBuilder view?
问题 I'm using JBuilder as to return some JSON. I have a index.json.jbuilder that generates the data, and I need to render it to a string. However, I'm not sure how to do this, since: @my_object.to_json and @my_object.as_json don't seem to go through JBuilder. How could I render the JBuilder view as a string? 回答1: I am rendering a collection of users as a json string in the controller like so: #controllers/users_controller.rb def index @users = User.all @users_json = render_to_string( template: