はじめに
エラーが解決せず、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) %>
エラー解決!!
気持ちいい!!