Last Updated: February 25, 2016
· mecampbellsoup

Rails image_tag pointer (Chrome-specific feature?)

Link to my rendered view in Chrome

In my Rails application (companies view), I wanted each 'company' to be displayed with its logo having a height of 125px. I figured I'd leave the width undefined so that the browser would render it according to each image's aspect ratio. Interestingly, Rails (or Chrome?) doesn't seem to recognize 'height' alone within the image_tag, but 'size' works exactly as I was hoping.

Here's my code:

    <div class="row-fluid">
    <div class="span9 list-group">
      <% @companies.each do |company| %>
          <ul class="well nav nav-pills">
                <li><%= link_to, company_path(company) %></li>
                <li><%= link_to(image_tag(company.logo, size: "125", class: "media"), company_path(company)) %></li>
      <% end %>