0

I am using theme that i bought for my rails project and author of the theme uses html5 data attributes to background image and the code looks like this

   <section class="jumbotron full-height relative" data-pages-bg-image="assets/images/banner_1.jpg" data-bg-overlay="black" data-overlay-opacity="0.5">

I found a resource on how to use data attributes with rails but its not really working for me. Here is the link that i found http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag

how would i convert the above code to work in rails(I'm using erb as a template engine)

3 Answers 3

1

You can use the same markup, however, you need to use RoR's helpers to get the image's url - you can use image_path:

   <section class="jumbotron full-height relative"
      data-pages-bg-image="<%= image_path('images/banner_1.jpg') %>"
      data-bg-overlay="black"
      data-overlay-opacity="0.5">
Sign up to request clarification or add additional context in comments.

Comments

0

I think this should work assuming you have the correct asset path:

image_tag("assets/images/banner_1.jpg", class: "jumbotron full-height relative" data-bg-overlay: "black", data-overlay-opacity: '0.5')

Comments

0

In addition, to the answers below, if you really want to convert it to erb template you could write it like this:

<%= content_tag(:section, "", class: "jumbotron full-height relative", "data-pages-bg-image" => "assets/images/banner_1.jpg", "data-bg-overlay" => "black", "data-overlay-opacity" => "0.5") %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.