For example, a very common pattern in plain HTML:
<a href="img/img-21-01.jpg">This pattern can create an image that can be clicked and enlarged.
<img src="img/img-21-01.jpg" alt="Image" class="img-fluid tm-header-img">
</a>
After I searched Google, read some articles in StackOverflow and Michael Hartl's Tutorial book. I conclude a simplier <%= link_to image_tag %> pattern to create a clickable image:
<%= link_to image_tag("picture01.jpg", alt: "Image Description"), image_path("picture01.jpg") %>
Again, in plain HTML:
<a href="img/img-21-01.jpg">
<img src="img/img-21-01.jpg" alt="Image" class="img-fluid tm-header-img">
</a>
I re-wrote into html.erb:
<%= link_to image_tag("img-21-01.jpg", :alt => "Image", :class => "img-fluid tm-header-img" ), image_path("img-21-01.jpg") %>
This is a simplified pattern to create a clickable image in html.erb (Ruby Embedded HTML).
The images in the home page:
Click the image to enlarge it:
References:
ruby on rails link_to an image
http://stackoverflow.com/questions/18484543/ruby-on-rails-link-to-an-image
image_path (ActionView::Helpers::AssetTagHelper) - APIdock
https://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_path
5.1.1 Site navigation
https://www.railstutorial.org/book/filling_in_the_layout#sec-adding_to_the_layout
Thanks for sharing such Programming details about ruby on rails and It is the interseting programming topic and to get some important information.on Ruby on Rails Online Training Bangalore
ReplyDeleteReally Good blog post.provided a helpful information.I hope that you will post more updates like this Ruby on Rails Online Training Bangalore
ReplyDelete