質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

1回答

891閲覧

本環境で出たTemplate::Errorを直したい

yozakura10

総合スコア8

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

0クリップ

投稿2020/10/27 06:20

1前提・実現したいこと
herokuを起動してエラーの確認をしたところTemplate::Errorが
出ており、そのエラーを解決したい

2発生している問題・エラーメッセージ

2020-10-26T10:37:33.229174+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id]): 2020-10-26T10:37:33.229175+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 5: <p class="card__summary"> 2020-10-26T10:37:33.229179+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 6: <%= "プロトタイプのキャッチコピー" %> 2020-10-26T10:37:33.229180+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 7: </p> 2020-10-26T10:37:33.229181+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 8: <%= link_to "by#{prototype.user.name}", user_path(current_user), method: :get, class: :card__user %> 2020-10-26T10:37:33.229181+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 9: </div> 2020-10-26T10:37:33.229181+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 10: </div> 2020-10-26T10:37:33.229182+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] 2020-10-26T10:37:33.229182+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] app/views/prototypes/_prototype.html.erb:8 2020-10-26T10:37:33.229183+00:00 app[web.1]: [f8aaa874-2dde-4c7e-a074-c59727357073] app/views/prototypes/index.html.erb:20

3該当のソースコード

app/views/prototypes/index.html.erb

html

1 2<main class="main"> 3 <div class="inner"> 4 <%# ログインしているときは以下を表示する %> 5 <% if user_signed_in? %> 6 <div class="greeting"> 7 <%= "こんにちは" %> 8 <%= link_to "#{current_user.name}", user_path(current_user), class: :greeting__link %> 9 <%# <%= link_to "#{current_user.name}", user_registration_path, class: :greeting__link %> 10 </div> 11 <% else %> 12 <div class="grid-6"> 13 <%= link_to "", new_user_session_path, class: "post" %> 14 <%= link_to "", new_user_registration_path, class: "post" %> 15 </div> 16 <% end %> 17 </div> 18 <%# // ログインしているときは上記を表示する %> 19 <div class="card__wrapper"> 20 <%# 投稿機能実装後、部分テンプレートでプロトタイプ投稿一覧を表示する %> 21 <%= render partial: "prototype", collection: @prototypes %> 22 </div> 23 </div> 24</main>

app/views/prototypes/_prototype.html.erb

html

1 2<div class="card"> 3 <%= link_to prototype_path(prototype.id),method: :get do %> 4 <%= image_tag prototype.image, class: 'card__img' if prototype.image.attached? %> 5 <% end %> 6 <div class="card__body"> 7 <%= link_to prototype.catct_copy, prototype_path(prototype.id), method: :get, class: :card__title%> 8 <p class="card__summary"> 9 <%= link_to prototype_path(prototype.id),method: :get do %> 10 <%= prototype.concept %> 11 <% end %> 12 </p> 13 <% if current_user %> 14 <%= link_to "by#{prototype.user.name}", user_path(current_user, method: :get, class: :card__user) %> 15 <% end %> 16 </div> 17</div> 18

app/controllers/users_controller.rb

ruby

1 2class UsersController < ApplicationController 3 before_action :move_to_index, except: [:index, :show] 4 5 6 def index 7 8 end 9 10 def new 11 @user = User.new 12 end 13 14 def edit 15 end 16 17 def show 18 @user = User.find(params[:id]) 19 @prototypes = @user.prototypes 20 end 21 22 23 def move_to_index 24 unless user_signed_in? 25 redirect_to action: :index 26 end 27 end 28 29 30 # private 31 # def user_params 32 # params.require(:user).permit(:name, :profile, :occupation, :position).merge(user_id: current_user.id) 33 # end 34 35end

app/controllers/prototypes_controller.rb

ruby

1 2class PrototypesController < ApplicationController 3 before_action :authenticate_user!, except: [:index, :show] 4 5 def index 6 @prototypes = Prototype.all 7 end 8 9 def new 10 @prototype = Prototype.new 11 end 12 13 def create 14 @prototype = Prototype.new(prototype_params) 15 if @prototype.save 16 redirect_to root_path 17 else 18 render :new 19 end 20 end 21 22 def show 23 @prototype = Prototype.find(params[:id]) 24 @comment = Comment.new 25 @comments = @prototype.comments 26 27 end 28 29 def edit 30 @prototype = Prototype.find(params[:id]) 31 unless current_user == @prototype.user 32 redirect_to root_path 33 end 34 end 35 36 def update 37 @prototype = Prototype.find(params[:id]) 38 if @prototype.update(prototype_params) 39 redirect_to prototype_path(@prototype) 40 else 41 render :edit 42 end 43 end 44 45 def destroy 46 prototype = Prototype.find(params[:id]) 47 prototype.destroy 48 redirect_to root_path 49 end 50 51 52 private 53 def prototype_params 54 params.require(:prototype).permit(:title, :catct_copy, :concept, :image).merge(user_id: current_user.id) 55 end 56 57 58end

4、自分でしたこと
user_path(current_user)のcurrent_userが怪しいと考え
@prototypesなどに変えたがそうすると違ったメソッドエラーが出てしまいます

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

user_path(current_user) の current_user が nil になっているようです。
user_signed_in? か current_user の method がおかしいのではないでしょうか。

投稿2020/10/27 21:22

winterboum

総合スコア23284

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問