ncrouch25 ncrouch25 - 1 year ago 76
HTML Question

Make rails carousel image a hyperlink

I'm trying to click on one of the images in my bootstrap carousel and have it redirect to another page on my site. Unfortunately I keep getting errors with it.

Here is the html/erb

This code does not function!

<div class="carousel-inner" role="listbox">
<div class="item active">
<%=link_to "#{image_tag("rsz_adobestock_44582832.jpg", :alt => "Slide1"), {:class => "img-responsive", :alt => "Responsive image"}}".html_safe, services_path %>
<div class="carousel-caption">

I'm doing something similar with the logo in the navbar, and that works fine.. Here is the code for that

This code functions perfectly

<div class="navbar-brand-image"> <%=link_to "#{image_tag 'rsz_1rsz_13logo.png'}".html_safe ,root_path %></div>

Finally, here is the error that I get with the code for the carousel.

/app/views/home/home.html.erb:17: syntax error, unexpected ',', expecting tSTRING_DEND
...582832.jpg", :alt => "Slide1"), {:class => "img-responsive",...
... ^):
app/views/home/home.html.erb:17: syntax error, unexpected ',', expecting tSTRING_DEND

Answer Source

you can try this

 <%= link_to(image_tag('rsz_adobestock_44582832.jpg',:alt => "Slide1", :class => "img-responsive"), services_path)%>

but please check if there is a image exist.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download