I'm trying to set a html user sign in a plain text rails mail view.
When I was using multi part, html_safe was working, but when I changed it to a single format view, it doesn't work, even on a html partial.
Here's the code:
send_proposals_email.text.erb -
<%= #greeting %>,
...
<%= #user.sign.html_safe %>
And it gets me a
<p>Atenciosamente,</p>
<p>Leandro Pons Malheiros</p>
Anyone knows a way to avoid spam and make this work?
Have you tried this strip_tags?
strip_tags(#greeting)
stip_tags Documentation
Related
I'm using https://foundation.zurb.com/emails.html to develop my email templates. For each and every template there are parts where I need to add eg. <%= params.someData %> but '<' gets escaped while compiling, so instead of being <%= params.someData %> it generates to <%= params.firstName %>
I see that https://foundation.zurb.com/sites/docs/panini.html is used for compiling but I'm not able to disabled this functionality in order for < character not to be escaped.
Please help.
You can use the integrated raw helper to do this.
Either use {{{{raw}}}}...{{{{/raw}}}} or <raw>...</raw>.
In gulfile.babel.js use pipe to replace <%= with <%=. I have had to do this with Adobe Campaign code, which doesn't work well with Zurb Foundation for email.
.pipe($.replace, '<%=', `<%=`)
Good luck.
I try to use scaffolding in rails to build a blog. I save my blog's content as :text.
However, when I see the view. It can only show in one line. It looks not good.
How can I solve this problem?
Your database stores text, not HTML. In HTML line breaks are ignored unless they are marked up with relevant HTML tags. For example, a break between two paragraphs should be marked by the end of one <p> element and the beginning of another, and a single line break should be represented by a <br> tag.
Rails' simple_format helper converts text to HTML by replacing line breaks with HTML tags.
So instead of something like this:
<p><%= #post.content %></p>
You would do this:
<%= simple_format #post.content %>
I have a blog that saves input from html input tags, saves them as XML into a sqlite3 database, and then finally renders the content inside of this tag.
<p>
<b>Content:</b>
<%= #post.content %>
</p>
I need this .content to be able to render HTML. Any ideas?
For these kind of situations, you have to use either:
Markup language like RedCloth,
Or an editor like CKEditor.
Using CKEditor is a breeze with the CKEditor gem
And please note if you are using Rails 3, you need to explicitly say you want raw HTML, like this:
<p>
<b>Content:</b>
<%= raw #post.content %>
</p>
New to RoR, so please don't kill me ;)
Was wondering why does not Rails 3 recognize HTML tags retrieved from database?
For example,
Name Content
Title <b>Great</b> Show Edit Destroy
I wanted to have Content to be bold and put < b > tag around it, when it retrieves from a database it looks like a plain English.
Any thoughts?
Thank you in advance.
If I got this right, you need to do this:
<%= myrecord.content.html_safe %>
to get "real" html and not just escaped html code.
Even though it is unsafe to deliberately output HTML from the DB, you should call raw on the content you're trying to print.
<%= raw #object.my_content %>
I have a Rails app (blog) that I am creating. Very basic stuff. In my content area I have a text area for the content of the post. I am needing to include some html in the text area (links, formating, etc).
<%= f.text_area :content %>
Is there another tag that I can use instead of text_area, that will allow me to do this?
Have you tried this in the views?
<%= content.html_safe %>
This is an old question but I guess there's a pretty straight forward view helper for this: sanitize. I presume you'd want to render the HTML tags entered by the user. For that purpose, save the content as a string and render as HTML using sanitize.
Example usage:
sanitize #post, tags: %w(strong em a code pre h2 h3 p blockquote ul ol li br),
attributes: %w(href class)
The tags option allows you to specify which tags to use and same with the html attributes.
The HTML safe method is actually .html_safe. Just tested on a text field.
For example:
<%= #item.description.html_safe %>
Are you looking for something similar to the bold, italic, ... options you get when posting in stackoverflow? If so, I would suggest Markitup, a text-editor plugin for jQuery. Once you get this set-up, you'll be able to enter mark up in your text area (e.g. Markdown, bbcode, ...). When you actually display the result on the page, you simply need to have Ruby parse the mark up language you chose.
E.g.
<%= #user.bio.bb_code %>
Using this method, you allow your users enter styled text in a safe fashion.
With the forthcoming Rails 6, you will be able to use a new rich_text_area tag to create a rich text editor in your forms like this:
<%= form_with(model: article) do |f| %>
<div class="field">
<%= f.label :content %>
<%= f.rich_text_area :content %>
</div>
<% end %>
See Action Text Rails Guide
text_area_tag is probably what you want.