ruby-on-railsrubyrefinerycmsrefinery

Rails is not rendering my HTML data attributes (RefineryCMS)


I have the following view refinery/portfolio/items/_item.html.erb from RefineryCMS and for some reason my data-attributes are not being rendered into the DOM.

From my understanding it seems that RefineryCMS is potentially removing them?

Rails 4.2.6 and latest master branch of RefineryCMS

Here is my ERB template:

<li class="col-md-3 col-xs-6 thumb">
  <a class="thumbnail" data-toggle="tab" data-target="#tab_<%= dom_id(item) %>">
    <%= image_tag(item.image.url, {:title => item.title}) %>
  </a>
</li>

Also tried:

<li class="col-md-3 col-xs-6 thumb">
  <%= link_to "", class: "thumbnail", data: { toggle: "tab", target: "#tab_#{dom_id(item)}" } do %>
    <%= image_tag(item.image.url, {:title => item.title}) %>
  <% end %>
</li>

It then renders HTML as:

<a class="thumbnail">
  <img title="title" src="/img.png" alt="alt_title">
</a>

Solution

  • After visiting the RefineryCMS Gitter chat, I was able to get the assistance I needed. The problem was recently in RefineryCMS 3 release they started sanitizing HTML data attributes.

    So I added the following configurations to my config/initializers/refinery/pages.rb:

    config.layout_template_whitelist = ["application"]
    config.add_whitelist_elements = %w[ source track ]
    config.add_whitelist_attributes = %w[ kind srclang placeholder controls data-target data-toggle ]