Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add class to img_tag in rails application

I want to add class to img_tag in rails application.

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

Here i have added class img-responsive to the image.

but i am getting error if i add this statement in line. i am not able to figure out what is missing in above line.

the error is:

app/views/pages/user_dashboard.html.erb:21: syntax error, unexpected ',', expecting ')'

How to resolve this issue.

like image 661
CJAY Avatar asked Dec 05 '25 17:12

CJAY


2 Answers

You have to put the class attributes inside the bracket . Like <%= image_tag("user.png", :class => "img-responsive") %> Hope this will solve your problem . Have a great day

like image 138
Mahabub Islam Prio Avatar answered Dec 08 '25 07:12

Mahabub Islam Prio


Here is the optimized version:

<%= image_tag("user.png", class: "img-responsive", alt: "user image") %>
like image 35
Dinesh Saini Avatar answered Dec 08 '25 07:12

Dinesh Saini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!