guides.rubyonrails.org

I18n keys ending with _html are automatically marked as HTML-safe when translating with t('.your_key_html'). When you're localizing a Rails application, some localized texts...

...Please visit our %{link} to learn more about the corporation .' You can then pass an HTML-safe string and it ends up as expected in your HTML: <%= t('.text_html...

...rendering of your page will not be affected. Tip If you care about their HTML being valid, your new element should contain a dash character (-) to mark it as a...

...custom element. Custom elements will be ignored during HTML validation, but their children will still be validated. Styling new elements Browsers will give unknown elements a default style of display...

simple_format ignores Rails' XSS protection. Even when called with an unsafe string, HTML characters will not be escaped or stripped! Instead simple_format calls sanitize on each of the...

...big", "cite"}> If you don't want user input with markup to appear as HTML, you need to escape yourself: simple_format(h(user_input)) Custom sanitization

...should have an efficient way to do it. Let's say I need this HTML structure: item 1 item 2 This card compares various approaches to fabricating DOM elements for...

...reader it is hard to follow which DOM structure is being created. Parsing a HTML string A very visual method is to embedded a string of HTML into your test...

...element as the main document viewport. In CSS, prefer to set overflow properties to html (or :root). Scrolling the main viewport with JavaScript The browser's main document viewport is...

...whatever scrolling element their implementation uses. I recommend to set any overflow property to html (or :root). Don't set a scrolling overflow-y value for both and , or funny...

...below is validated for the current list of browsers we support. By default your html and body elements are only as high as the actual page content inside their container...

...If you only have two lines of text in your page, your html and body elements will only be around 40 pixels high, regardless of the size of your browser...

However, your application must do one thing by itself: When sending HTML e-mails, you should include a plain-text body or tools like SpamAssassin will apply...

Actually, you may want to configure premailer-rails, and maybe tweak your HTML e-mail views a bit. Here are some suggestions. Open Rails' ActionMailer Previews and you...

This card describes different flavors for concatting HTML safe strings in a helper method in Rails. You might want to use the tag helper instead of the content_tag helper...

...the tag helper knows all self closing tags). Example We want to generate HTML like this: Navigation Left Right Below you can find multiple helper variants that generate this markup...

...wrap at a soft hyphen, it is turned into a regular hyphen character (‐). The HTML entity for a soft hyphen is &shy;. Use it to mark division opportunities in a...

...hyphenized. E.g. brand names like makandra should not be hyphenated. Option 3: wbr-tags HTML has a tag you can use to mark word wrap opportunities: Do nau dampf schiff...

...in its own window, like a PDF. Capybara/Selenium freaks out because there is no HTML document on the other side. Below you can find multiple methods how to test file...

For outputting a given String in HTML, you mostly want to replace line breaks with or tags. You can use simple_format, but it has side effects like keeping some...

If you only care about line breaks, you might be better off using a small, specialized helper method: def format_linebreaks(text) safe_text = h(text) paragraphs = split_paragraphs...

github.com

Capybara-screenshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest. Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. Screenshots are saved...

...also use Rails' built-in ScreenshotHelper module available for Rails >= 5. Including assets in HTML screenshots for prettier presentation Note Capybara takes two kinds of screenshots: a regular image and...

...template for a format that the client understand. This means when all you are HTML templates, a request that only accepts application/json will raise an error: An ActionView::MissingTemplate occurred...

You can choose not to care. Since e.g. making JSON requests for HTML services is not supported use of your page, you don't have to support them...

developer.mozilla.org

...HTML's accepts a single file. You can allow multiple files via . But sometimes, selecting multiple files is not enough and can be cumbersome for the user. Enter webkitdirectory:

...feel future-proof. On JavaScript file objects, webkitRelativePath is supported similarly to webkitdirectory in HTML. As a fallback for older browsers you can use name (which won't include any...

...the environment name in a data-environment of your . E.g., in your application layout: <html data-environment=<%= Rails.env %>> Now you can say in a piece of Javascript: if (document.documentElement.dataset.environment == 'test...

} else { // Code that should happen for other environments } Or in your CSS / Sass: html[data-environment="test"] { * { text-transform: none !important; } } See also Cucumber: Detect if the current Capybara...

...button to render somewhere else, it should still be the first button in the HTML source. You can use CSS (e.g. flex-direction) to change the visual order without changing...

...the order in the HTML markup...

...might upload content that hurts other users. Our primary concern here is users uploading .html or .svg files that can run JavaScript and possibly hijack another user's session.

...executing files that were downloaded from the internet. Attack example: Hijacking sessions with uploaded HTML or SVG files You run an app myapp.com. The attacker runs an app evil.com.

The attached compiler() function below applies JavaScript behavior to matching HTML elements as they enter the DOM. This works like an Unpoly compiler for apps that don't use Unpoly...

...Custom Elements or any other mechanism that pairs JavaScript with HTML elements. The compiler() function is also a lightweight replacement for our legacy $.unobtrusive() helper (no jQuery required).

github.com

...class GroupsController < ApplicationController def members group_ids = params[:group_ids].split(',') group_ids_and_html = {} group_ids.each do |group_id| group = load_group(group_id) group_ids_and_html[group_id...

...render_group_html(group) end render json: group_ids_and_html end private def load_group(group_id) Group.find(group_id) end def render_group_html(user_group)

HTML describes what is on a web page: headings, paragraphs, lists, links, images and forms. Everything you build from here on attaches to it — Rails renders HTML, your CSS selects...

Work on this lesson in teacher mode. Note Many trainees arrive already knowing HTML. If that is you, read the learning goals, confirm you could do the exercises, and...

From at least Rails 4, the ActionView tag helper turns Array values of HTML options into a single space-separated string. This means you can pass an array to :class...

To bind an HTML value to ng-bind-html, you need to mark it as "trusted" first. Among other ways, you can do so with a custom filter.

...Coffeescript...: @app.filter 'htmlSafe', ['$sce', ($sce) -> $sce.trustAsHtml ] # ...or JS: app.filter('htmlSafe', [ '$sce', function($sce) { return $sce.trustAsHtml; } ]); # Usage: This is a replacement for the ng-bind-html-unsafe directive which has been...

...only available for input[type=text], textarea Related cards Preventing interactivity on elements using HTML or CSS

Learning goals You can explain how Action Mailer works: mailer classes, text and HTML views, and delivery methods that differ per environment. You can implement and test a mailer...

...from form models rather than from core model callbacks. You know the constraints of HTML e-mail and where to look up what mail clients support. Resources