LoginSignup
2
2

More than 1 year has passed since last update.

エラー発生(未解決)→解決!!

Last updated at Posted at 2021-07-27

はじめに

エラーが解決せず、12時間が経ちました。
一体何が悪いかさっぱり分かりません。
もう永久にブラウザが表示されないのではないかと思っています。

過去にこんなことがあったんだということを忘れないためにも、
備忘録として残します。

コード

routes.rb

Rails.application.routes.draw do
  devise_for :users
  get 'prototypes/index'
  root to: "prototypes#index"

  resources :prototypes

end

prototypes_controller.rb

class PrototypesController < ApplicationController
  def index
    @prototypes = Prototype.all
  end

  def new
    @prototype = Prototype.new
  end

  def create
    @prototype = Prototype.new(prototype_params)

    if @prototype.save
      redirect_to root_path
    else
      render :new
    end
  end

  private

  def prototype_params
    params.require(:prototype).permit(:title, :catch_copy, :concept, :image ).merge(user_id: current_user.id)
  end

end

index.html.erb

<main class="main">
  <div class="inner">
    <% if user_signed_in? %>
      <div class="greeting">
        <%= "こんにちは、" %>
        <%= link_to "#{current_user.name}さん", root_path, class: :greeting__link%>
      </div>
    <% end %>
    <div class="card__wrapper">
      <%= render partial: 'prototype', collection: @prototypes %>
    </div>
  </div>
</main>

_prototypes.html.erb

<div class="card">
  <%= image_tag "プロトタイプの画像", root_path, class: :card__img%>
  <div class="card__body">
    <%= link_to "プロトタイプのタイトル", root_path, class: :card__title%>
    <p class="card__summary">
      <%= "プロトタイプのキャッチコピー" %>
    </p>
    <%= link_to "by プロトタイプの投稿者名", root_path, class: :card__user %>
  </div>
</div>

ここが間違いではないか

_prototypes.html.erbの

<%= image_tag "プロトタイプの画像", root_path, class: :card__img%>

が間違いだと思う。
しかし、image_tagとlink_toの記述の違いがわからない。
ここから復習します。

終わりに

今回は完全に私事で記事を書いてしまいました。

この問題が明日に、
未解決→解決にできるよう精一杯エラーと向き合います。

まずは落ち着いて、リフレッシュしながら頑張ります。

追記

案の定、以下が間違いでした!!

(誤)

<%= image_tag "プロトタイプの画像", root_path, class: :card__img%>

(正)

<%= link_to image_tag(prototype.image, class: "card__img" ), prototype_path(prototype.id) %>

エラー解決!!
気持ちいい!!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2