Andrew Breunig
Andrew Breunig

Reputation: 155

rails html image_tag not rendering classes

I'm building a blog app in Ruby on Rails. I have an "About" view where I'd like to load an image and style it with some bootstrap classes.

Currently, the image is loading successfully and rendering on the page, but it doesn't have the styling I want and when I use the Chrome Inspector I see that the browser is totally ignoring the classes (skips over them).

I'm porting this project over from a basic web page, and before porting it to Rails, the image was styled correctly.

Here is my Rails code:

<%= image_tag asset_path 'filename.jpg', class: "img-responsive img-rounded center-block", alt: "Image description" %>

And this is what Chrome Inspector sees:

<img src="/assets/filename.jpg" alt="Image description">

No classes! Where did they go?

Here is my HTML code from the old page, which works:

<img src="assets/images/filename.jpg" class="img-responsive img-rounded center-block" alt="Image description" />

A fresh set of eyes would be appreciated. What am I missing?

Upvotes: 1

Views: 479

Answers (1)

Sean Huber
Sean Huber

Reputation: 3985

Try putting parentheses around your argument to the asset_path method:

<%= image_tag asset_path('filename.jpg'), class: "img-responsive img-rounded center-block", alt: "Image description" %>

Upvotes: 2

Related Questions