How to use the image_tag with bootstrap class: “img-responsive” ? Chapter 11

心已入冬 提交于 2019-12-10 20:11:18

问题


The reason I’m asking the question is to get some help me with a really annoying syntax error. I'm using chapter 11 so I can build a blog section on my new site with images, everything is working apart from when i try to add class: "img-responsive" to this line.

<%= image_tag image_article.picture.url if image_article.picture? %>

I just can't figure out the correct syntax to add class: "img-responsive".

The image is uploading fine but it breaks out of the col-md-6 container, and displays the full image breaking the page-layout, so it's all working locally apart from when I try to add class: “img-responsive” in parentheses or brackets, every way I try crashes the app, so I’m stuck. I've looked around for other solutions, i've found a gem that works with carrierwave ...

responsive-images gem

but this seems to be like using a sledgehammer to crack a nut, so far all the other problems i've had i've figured out, but this is really annoying. I can't find anything with carrierwave resizing that fits the bill for responsive images, surely i can use the img-responsive class?

Regards Shaun


回答1:


Try to give the tag inside brackets

<%=image_tag(image_article.picture.url, class: "img-responsive") if image_article.picture?%>



回答2:


Try this..it worked for me.. in place of xyz.png, add the image name as in Assets folder.

<%= image_tag("xyz.png", class: "img-responsive img-thumbnail img-circle") %>




回答3:


Bootstrap 4 uses class: 'img-fluid' instead of 'img-responsive'

Try:

<%= image_tag image_article.picture.url, class: 'img-fluid' if image_article.picture? %>



回答4:


Have you tried this:

<%= image_tag image_article.picture.url, class: "img-responsive" if image_article.picture? %>


来源:https://stackoverflow.com/questions/31368682/how-to-use-the-image-tag-with-bootstrap-class-img-responsive-chapter-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!