How do I make two html documents per action?

After clicking the save user button, I need to render a new page and render_to_string a preview of that page in the same time. To save it to the database.

So I got a DoubleRenderError exception.

Am I trying to stub @performed?

But clearing the layout after the first render. Any ideas?

Thanks for answers!

+2


source to share


2 answers


I have used render_to_string and render successfully for the same request.



I think you need to make sure you are calling render_to_string first. YMMV

+1


source


I will probably do it with rack middleware.

class ResponseLoggerMiddleware
    def initialize(app)
        @app = app
    end

    def call(env)
        status, headers, response = @app.call(env)
        ... save your response to the database ...    
        [status, headers, response]
    end
end

      



You can install it like this:

# environment.rb
Rails::Initializer.run do |config|
    ...
    config.middleware.use ResponseLoggerMiddleware
end 

      

0


source







All Articles