Is there a way to capture the output of my view file after it is rendered?
I basically want to save the full HTML output into a database after the page renders.
You could use render_to_string, then stick it in the db and send the string containing the rendering to the browser. See RoR render_to_string doc.
What I ended up using is the following:
after_filter :save_if_necessary
and what I stored was
self.response.body
Related
How would I go about achieving the following
I have some HTML data triggered from an Evernote new note action
I need to pass this HTML string to a website via an http post with form variables
I then need to catch the resulting web page text in a variable to use in my next action.
For clarity the website simply takes some HTML and converts it to markdown passing it back out as the body of the resulting page
Regards in advance
Dan
Sweet! So I've got this working. In my example, text is some html I pulled out of a dummy previous step:
The output is:
Which has the markdown as a key. If you want to tweak other data based on the api params, you can do that as GET params below html
Let me know if you've got any other questions!
Essentially I'm trying to implement a way so that users can edit slim that is stored in the database.
For example they would use the form to create a new page and insert the html for that page in a text field which would be saved in the database. I want to allow them to edit that page in slim. By the way the html stored is slim not plain html.
If I store slim in the database how do I get rails to render the html properly on the client side in production? So in other words would rails automatically do this since the view is being render like so:
views/page/view.html.slim
page.header
page.content
page.footer
or would I have to figure out a way to convert on the fly? I might be making this more complicated then I should but I'm new to this
If I understand you correctly you want to convert the slim to Html and output that in your views.
This is directly from slims doc. This is how it processes slim files and outputs it.
Tilt.new['template.slim'].render(scope)
Slim::Template.new('template.slim', optional_option_hash).render(scope)
Slim::Template.new(optional_option_hash) { source }.render(scope)
so in short
Slim::Template.new(page/view.html.slim).render
put that in a module to make it prettier and I think you're good. You may want to use rails path helper to get the direct link for the view. You may also want to consider figuring out a way to catch the errors in indentation so that your output doesn't bug out in production. Some kind of validation that prevents it from saving if not properly formatted should help.
As stated, how do I take everything ever rendered from a controller action in Rails through a method in a gem so I can parse the output for specific text?
Try using
response.body
According to http://api.rubyonrails.org/classes/ActionDispatch/Response.html#method-i-body this returns the content of the response as a string. This contains the contents of any calls to render.
How do I export all my rendered view to an html file? I want to save the view to a file rather than display it to the screen. Is this possible?
Instead of render call render_to_string and save the returned string into an file.
(see: http://apidock.com/rails/AbstractController/Rendering/render_to_string)
This sort of sounds like Dynamic Page Caching. There is a Railscasts on this topic. It is rather dated, unless you subscribe (there is a revised version with subscription).
http://railscasts.com/episodes/169-dynamic-page-caching
I would like to use the same set up as Photoswipe, only pass a div or index.html through instead of an image.
Here is the link to the photoswipe package:
http://www.photoswipe.com
Please let me know if this isn't possible! Thank you!
Since you use get method to load more images you can get html instead of images.
Just you need to print html as you require in your ajax request. And then you can display the html by using javascript i.e when you get html in your data variable.