[RUBY] How to move to the details screen by clicking the image

environment

This article uses Ruby 2.6.5 installed on macOS Catalina 10.15.6.

Purpose

On the report list screen, click the image of the posted report to see the details.

Conclusion: use nesting

To transition to the details screen when clicking the image, you can solve it by using nesting in the link_to method. Enclose in do ~ end.

html:index.html.erb


    <%= link_to report_path(report.id) do %>
      <div class="content_post">
        <%= image_tag report.image if report.image.attached? %>
        <p>Customer name:<%= report.name %></p>
        <span class="name">
          <%= report.date %>
        </span>
      </div>
    <% end %>

Summary

Nesting is a very useful feature because you can specify which report to comment on when setting up routing! I hope it helps people with similar worries and bumps into the wall!

Recommended Posts

How to move to the details screen by clicking the image
How to return to the previous screen by Swipe operation
How to display products by category on the same list screen
How to pass the value to another screen
[Rails] How to decide the destination by "rails routes"
How to remove the underline displayed by Rails link_to
[Android Studio] [Java] How to fix the screen vertically
How to judge the click of any area of the image
[Rails] How to display an image in the view
How to dynamically change the column name acquired by MyBatis
How to connect the strings in the List separated by commas
[Rails] How to display the list of posts by category
How to use the link_to method
[Rails] How to convert the URI of the image sent by http to https when using Twitter API
How to use the include? method
How to use the form_with method
[Rails carrier wave] How to not transition to the error screen even if the image upload is not selected
[Rails] How to prevent screen transition
How to use the wrapper class
How to make a splash screen
Replace preview by uploading by clicking the image in file_field of Rails
[JQuery] How to preview the selected image immediately + Add image posting gem
How to add the delete function
How to distinguish ubuntu cloud image
[Rails 5] How to display the password change screen when using devise
[Swift] How to set an image in the background without using UIImageView.
How to make the schema of the URL generated by Rails URL helper https
How to crop an image with libGDX
How to prevent duplicate processing by addEventListener
[Java] How to use the File class
How to delete the wrong migration file
[Java] How to use the hasNext function
Display an image on the base64 screen
How to blur an image (super easy)
How to put out the error bundling
[Java] How to use the HashMap class
How to delete the migration file NO FILE
[Rails] How to use the map method
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to determine the number of parallels
How to output Java string to console screen
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
[Swift] How to implement the countdown function
How to change the timezone on Ubuntu
How the website is displayed on the screen
Ransack sort_link How to change the color!
[Processing × Java] How to use the class
How to sort the List of SelectItem
How to install the legacy version [Java]
How to find the tens and ones
How to get the date in java
[Swift5] How to implement standby screen using'PKHUD'
[Swift5] How to create a splash screen
[Processing × Java] How to use the function
How to implement image posting using rails
[Java] How to use the Calendar class
Summarized how to climb the programming stairs
[Rails6] How to connect the posting function generated by Scaffold with the user function generated by devise