Q:

rails: render a template into a variable

I want to get my templates rendered and the html/json saved in variables in some actions in my application. Something like: 
def show
  @var = Var.find(params[:id])
  x = render "tmeplate1", format: :json

  render nothing: true
end

When I call this actions I get an error: AbstractController::DoubleRenderError in VarsController#show
any other way I can use the templates and not rendering twice ?

A:

You have written render two times in the method that why double render error comes. Use render_to_string
x = render_to_string "tmeplate1", format: :json 

