I want to reduce simple mistakes. To command yourself.

Introduction

Today, I will summarize what I was learning and took about 30 minutes to solve.

problem

Even if you want to go to the detail page, you do not jump to the page you want, and even if you touch any link image, you will go to the same detail page.

Path to solution


def show
    @prototype = Prototype.find(params[:id])
end

I think that the action of the controller is wrong, and I look back many times, but I can't find any problem. Find the id in the Prototype table and put it in an instance variable.

Next, to see the code of the part to touch when jumping to the detail page.

<%= link_to image_tag(prototype.image), prototype_path(prototype.user.id)%>

Yes, I wanted to find the id of the prototype by putting the .user in the linked path, but I was looking for the id of the ʻuser` table. So, when I entered as a user with id = 1, I was on the first detail page no matter which link image I touched. A mistake that occurred because the prototype table and the user table are associated.

Correctly ↓

<%= link_to image_tag(prototype.image), prototype_path(prototype.id)%>

Recommended Posts

I want to reduce simple mistakes. To command yourself.
I want to pass the startup command to postgres with docker-compose.
Swift: I want to chain arrays
I want to use FormObject well
I want to convert InputStream to String
I want to docker-compose up Next.js!
I want to develop a web application!
I want to write a nice build.gradle
I want to eliminate duplicate error messages
I want to make an ios.android app
I want to display background-ground-image on heroku.
I want to use DBViewer with Eclipse 2018-12! !!
I want to RSpec even at Jest!
I want to write a unit test!
I want to install PHP 7.2 on Ubuntu 20.04.
I want to use @Autowired in Servlet
I want to target static fields to @Autowired
I want to do team development remotely
I want to test Action Cable with RSpec test
I want to sort by tab delimited by ruby
I want to output the day of the week
Run R from Java I want to run rJava
[Swift] I want to draw grid lines (squares)
I want to send an email in Java.
I want to graduate from npm install properly [2020]
I want to use arrow notation in Ruby
[Ruby] I want to do a method jump!
I want to var_dump the contents of the intent
I want to simply write a repeating string
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
I want to play with Firestore from Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I want to truncate after the decimal point
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
I want to delete files managed by Git
I want to get the value in Ruby
I want to reduce the number of unnecessary queries. From considering counter_cache to introducing counter_culture.
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
I want to call a method of another class
I want to do something like "cls" in Java
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to embed any TraceId in the log
Pointcut Expression I want to specify more than one
I want to use fish shell in Laradock too! !!
I tried to decorate the simple calendar a little
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I learned stream (I want to convert List to Map <Integer, List>)
I want to use a little icon in Rails
I tried to reduce the capacity of Spring Boot
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to apply ContainerRelativeShape only to specific corners [SwiftUI]
I want to authenticate users to Rails with Devise + OmniAuth