I've created a form with several fields, and many of them use ckeditor, I know that separately I can generate a pdf of each field, but I have normal fields (string, date), and I wanted them to be in pdf. I tried with the prawn but it does not render the ckeditor html tags. How to generate a pdf with these fields, those of the ckeditor rendering the html tags, and the others appearing normally?
Use the following command to process the following html tags present in the ckeditor for prawn to understand:
ActionView::Base.full_sanitizer.sanitize(#string)
Related
I'm rendering the PDF data from the output of CK editor (What you see is what you get editor).
The output from that editor would be included with all the HTML, CSS tags in the content. For that I had used 'html_safe' attribute in the show page. But when I try to use the same attribute in the PDF prawn syntax its not working. Can someone please guide me how to get the pure content without all the HTML tags in Prawn PDF?
Thanks in advance.
After a long a Google search I finally got an answer which I wish to share with you.
As html_safe is the action view method in rails, It can not be used in ruby syntax of Prawn pdf.
So for that we can use:
ActionView::Base.full_sanitizer.sanitize(#string)
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags
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.
I am using select2 in tagging mode to create and edit tags. There is an annoying behavior which is that there is a delay between when the page loads and when the tags appear. Since the tags can spill onto two lines, after the tags appear the whole page readjusts when the content below the tags box is pushed down.
The delay is caused by select2 converting the input HTML tag into the necessary HTML elements for each tag.
The delay could be avoided if the select2 didn't generate the HTML for the tags, but instead I generated it on the server-side and it was included in the original page load. Then the position of elements below the tags field would never change.
Is there a way to have select2 attach itself it existing - pre-rendered - HTML, rather than creating the HTML itself?
Does anyone know of a tag field components that supports this? All of the components I have seen start with an input tag and then generate the HTML dynamically using Javascript.
I could not find a satisfactory answer, so I created a JQuery plugin specifically for my use case: https://github.com/k1w1/rendered-multi-select
It has Rails helper to render the HTML for the control on the server, then the Javascript events are attached when the page loads. This results in faster and flicker free loading.
The auto_link_usernames_or_lists can't deal with html well.
when I am trying to generate link using html tag. when you have mention string inside single html element then it not generate link but if you have more than two tag it generate link correctly
auto_link_usernames_or_lists('<p>#blankyao</p>') O/P - No link generated
auto_link_usernames_or_lists('<span><p>#blankyao</p><span>') O/P - Link generated properly
I'm porting an application to Rails 3.
We're an e-commerce site and naturally we send copies of tax invoices by email. We use plain text, so a .text.erb seems logical.
We also display invoices in an area of the user profile, inside <pre></pre> tags. Is there are way I can share a partial between plain text mailer templates, and views in HTML? If I try to render "shared/invoice" inside my HTML ERB template, it says the partial doesn't exist, and that's because it's a .text.erb partial.
What are my options, without duplicating code?
I haven't tried this in Rails 3, but in Rails 2 you could specify the format of the partial. Might be worth giving it a go on Rails 3.
render :partial => "shared/invoice.text.erb"