how to add inline css to rails link_to helper

Tags: html,css,ruby-on-rails,ruby-on-rails-5

Problem :

am on rails 5 and my categories have images. i want to use those images as backround images but when i set in the styling the url do not change

<div class="grid-category">
    <% @servicescategories.each do |category| %>

    <%= link_to servicecategories_path(slug: category.slug ), :style=>'background-image: asset-data-url("category.category_image");',  class: "category-item" do %>

        <h3> <%= %></h3>

        <% end %>
    <% end %>

what am i doing wrong here

Solution :

You need to interpolate the value of category.category_image

<%= link_to servicecategories_path(slug: category.slug ),  
            class: "category-item" do %>

  <div style="background-image: url(<%= asset_path('category.category_image') %>)">
    <h3> <%= %></h3>

<% end %>

    CSS Howto..

    how to include css style to modify existing placeholder

    How do I vertically center an image whose size can change in a div?

    How to align text and buttons next to canvas (WebGL + JavaScript + CSS)

    CSS How to create a container with non-linear borders

    How to rotate a chart 90 degrees including the text values?

    How to fade in and out text and css using jquery

    How to resize an image cropping it equally on each side with CSS

    How to uniformly darken colors?

    How to solve CSS background transparency?

    How to change tooltip style in jQuery vmap?

    How would you code this: The SO Menu [closed]

    How to manually apply styles from particular style sheet to an element?

    How to add new value to current css value [closed]

    How to customise button ( CSS, HTML)

    How to CSS pairs of DIV text left/right of center

    How do I fix this div overflow?

    How to line up the bottom of side-by-side Div layers in CSS

    How can I create two columns of text next to each other using CSS?

    How to center vertically child elements inside div [duplicate]

    How to align an image inside a DIV without adding new classes using CSS

    How to find all possible CSS Styles and Attributes of an Element?

    How can I line up the two containers in view?

    rails redirect_to notice - how to apply css

    How to auto adjust wrapper height when padding is applied to inner elements

    Dynamic HTML 3 layers nested quotes - how to do?

    How to make Flexbox span multiple lines?

    How to dynamically add more width inside a div?

    Sub menu wont show when menu item hovered over (css html)

    How to keep block elements inline and also correctly centered?

    How to morph multi-part css properties with Mootools Fx?