Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 798
benams Avatar asked Feb 01 '26 23:02

benams


1 Answers

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 
like image 171
Sachin R Avatar answered Feb 03 '26 16:02

Sachin R