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

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

新規登録して質問してみよう
ただいま回答率
85.47%
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

2回答

1038閲覧

本環境でおきたエラーを直したい

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/26 10:25

編集2020/10/26 11:20

herokuにアプリを更新したあと
We're sorry, but something went wrong.
If you are the application owner check the logs for more information
というエラーが出たのでターミナルheroku logs --tailをしたところ
以下のエラー文が出ました(した10行だけ書きます)

2020-10-26T09:36:36.741765+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 2020-10-26T09:36:36.741766+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id]): 2020-10-26T09:36:36.741767+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 5: <p class="card__summary"> 2020-10-26T09:36:36.741767+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 6: <%= "プロトタイプのキャッチコピー" %> 2020-10-26T09:36:36.741768+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 7: </p> 2020-10-26T09:36:36.741768+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 8: <%= link_to "by#{prototype.user.name}", user_path(current_user), method: :get, class: :card__user %> 2020-10-26T09:36:36.741769+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 9: </div> 2020-10-26T09:36:36.741769+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 10: </div> 2020-10-26T09:36:36.741769+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] 2020-10-26T09:36:36.741770+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] app/views/prototypes/_prototype.html.erb:8 2020-10-26T09:36:36.741770+00:00 app[web.1]: [faaca404-a2ec-4d82-a673-3f1e008ef659] app/views/prototypes/index.html.erb:20 2020-10-26T10:11:20.851973+00:00 heroku[web.1]: Idling 2020-10-26T10:11:20.854855+00:00 heroku[web.1]: State changed from up to down 2020-10-26T10:11:21.811353+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2020-10-26T10:11:21.841059+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish 2020-10-26T10:11:21.843060+00:00 app[web.1]: === puma shutdown: 2020-10-26 10:11:21 +0000 === 2020-10-26T10:11:21.843062+00:00 app[web.1]: - Goodbye! 2020-10-26T10:11:21.843063+00:00 app[web.1]: Exiting 2020-10-26T10:11:21.962814+00:00 heroku[web.1]: Process exited with status 143

気になったのは
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id]):
というところですがどのファイルをどうやって直せばいいかわかりません

関係ありそうなコードを載せます
config/routes.rb

ruby

1Rails.application.routes.draw do 2 devise_for :users 3 root to: "prototypes#index" 4 resources :users, only: [:new, :edit, :update, :show] 5 resources :prototypes, only: [:index, :new, :create, :show, :edit, :update, :destroy,] do 6 resources :comments, only: [:create] 7 end 8 9 devise_scope :user do 10 get '/users/sign_out' => 'devise/sessions#destroy' 11 end 12 13end 14 15 16

app/controllers/prototypes_controller.rb

ruby

1class PrototypesController < ApplicationController 2 before_action :authenticate_user!, only: [:index, :show, :new] 3 before_action :move_to_index, expect: [:index] 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.includes(:user) 26 27 end 28 29 def edit 30 @prototype = Prototype.find(params[:id]) 31 if @prototype.user_id == current_user.id 32 render :edit 33 else 34 redirect_to root_path 35 end 36 end 37 38 def update 39 prototype = Prototype.find(params[:id]) 40 if prototype.update(prototype_params) 41 redirect_to prototype_path 42 else 43 render :edit 44 end 45 end 46 47 def destroy 48 @prototype = Prototype.find(params[:id]) 49 if @prototype.destroy 50 redirect_to root_path 51 end 52 end 53 54 def move_to_index 55 unless user_signed_in? && current_user.id == @prototype.user_id 56 redirect_to action: :index 57 end 58 59 private 60 def prototype_params 61 params.require(:prototype).permit(:title, :catct_copy, :concept, :image).merge(user_id: current_user.id) 62 end 63 64 65end

app/controllers/users_controller.rb

ruby

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

app/views/prototypes/show.html.erb

html

1<main class="main"> 2 <div class="inner"> 3 <div class="prototype__wrapper"> 4 <p class="prototype__hedding"> 5 <%= "プロトタイプのタイトル"%> 6 </p> 7 8 <%= link_to "by #{@prototype.user.name}さん" , user_path(@prototype.user), class: :prototype__user %> 9 <%# 上の記述で@prototypeにuserモデルからnameカラムを持ってくるコードができた %> 10 <%# プロトタイプの投稿者とログインしているユーザーが同じであれば以下を表示する %> 11 <% if current_user == @prototype.user%> 12 <div class="prototype__manage"> 13 <%= link_to "編集する", edit_prototype_path(@prototype), class: :prototype__btn %> 14 <%= link_to "削除する", prototype_path(@prototype), method: :delete, class: :prototype__btn %> 15 </div> 16 <% end %> 17 <%# // プロトタイプの投稿者とログインしているユーザーが同じであれば上記を表示する %> 18 <div class="prototype__image"> 19 <%= image_tag @prototype.image %> 20 </div> 21 <div class="prototype__body"> 22 <div class="prototype__detail"> 23 <p class="detail__title">キャッチコピー</p> 24 <p class="detail__message"> 25 <%= @prototype.catct_copy%> 26 </p> 27 </div> 28 <div class="prototype__detail"> 29 <p class="detail__title">コンセプト</p> 30 <p class="detail__message"> 31 <%= @prototype.concept%> 32 </p> 33 </div> 34 </div> 35 <div class="prototype__comments"> 36 <%# ログインしているユーザーには以下のコメント投稿フォームを表示する %> 37 <% if current_user %> 38 <%= form_with model: [@prototype, @comment], local: true do |f|%> 39 <%# (model: [@prototype, @comment], local: true)にするといいかも %> 40 <div class="field"> 41 <%= f.label :text, "コメント" %><br /> 42 <%= f.text_field :text %> 43 </div> 44 <div class="actions"> 45 <%= f.submit "送信する", class: :form__btn %> 46 </div> 47 <% end %>   48 <% end %> 49 <%# // ログインしているユーザーには上記を表示する %> 50 <ul class="comments_lists"> 51 <%# 投稿に紐づくコメントを一覧する処理を記述する %> 52 <% if @comments %> 53 <% @comments.each do |comment| %> 54 <li class="comments_list"> 55 <%= link_to comment.text + " (#{@prototype.user.name})", user_path(current_user), class: :comment_user %> 56  <% end %> 57 <% end %> 58 </li> 59 <%# // 投稿に紐づくコメントを一覧する処理を記述する %> 60 </ul> 61 </div> 62 </div> 63 </div> 64</main>

app/views/users/show.html.erb

html

1<div class="main"> 2 <div class="inner"> 3 <div class="user__wrapper"> 4 <h2 class="page-heading"> 5 <%= @user.name + "さんの情報" %> 6 </h2> 7 <table class="table"> 8 <tbody> 9 <tr> 10 <th class="table__col1">名前</th> 11 <td class="table__col2"><%= @user.name %></td> 12 </tr> 13 <tr> 14 <th class="table__col1">プロフィール</th> 15 <td class="table__col2"><%= @user.profile %></td> 16 </tr> 17 <tr> 18 <th class="table__col1">所属</th> 19 <td class="table__col2"><%= @user.occupation %></td> 20 </tr> 21 <tr> 22 <th class="table__col1">役職</th> 23 <td class="table__col2"><%= @user.position %></td> 24 </tr> 25 </tbody> 26 </table> 27 <h2 class="page-heading"> 28 <%= @user.name + "さんのプロトタイプ" %> 29 </h2> 30 <div class="user__card"> 31 <%# 部分テンプレートでそのユーザーが投稿したプロトタイプ投稿一覧を表示する %> 32 <%= render partial: "prototypes/prototype", collection: @prototypes %> 33 </div> 34 </div> 35 </div> 36</div> 37

app/views/prototypes/_prototype.html.erb

html

1<div class="card"> 2 <%= image_tag prototype.image, class: 'card__img' if prototype.image.attached? %> 3 <div class="card__body"> 4 <%= link_to 'プロトタイプのタイトル', prototype_path(prototype.id), method: :get, class: :card__title%> 5 <p class="card__summary"> 6 <%= "プロトタイプのキャッチコピー" %> 7 </p> 8 <%= link_to "by#{prototype.user.name}", user_path(current_user), method: :get, class: :card__user %> 9 </div> 10</div>

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

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

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

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

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

guest

回答2

0

<%= link_to "by#{prototype.user.name}",
ということは、prototype に関連するuserの詳細を表示させたいのでしょうから
user_path(current_user) は???
user_path(prototype.user) では?

投稿2020/10/26 11:04

winterboum

総合スコア23366

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

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

0

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id]):

とのことで、引数にIDが必須だけどパス(=user_path(current_user))のcurrent_userがnilであり、IDが渡っていないために起きているエラーかと思われます。

ログインをして、current_userがnilにならないようにする
またはcurrent_userがあるときのみ表示するようにするなどで解決できるかと思いました。

<% if current_user %> <%= link_to "by#{prototype.user.name}", user_path(current_user), method: :get, class: :card__user %> <% end %>

投稿2020/10/26 10:45

hatsu

総合スコア1809

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

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

yozakura10

2020/10/26 10:58

<% if current_user %> <%= link_to "by#{prototype.user.name}", user_path(current_user), method: :get, class: :card__user %> <% end %> にしたのですがエラー内容が変わりませんでしたログインをして、current_userがnilにならないようにする またはcurrent_userがあるときのみ表示するようにするなどで解決するには どうしたら良いでしょうか
hatsu

2020/10/26 11:01

ちなみにローカル環境の非ログイン状態でも再現しますでしょうか? あとroutes.rbファイルの中身も質問欄に追記いただけると参考になるかもです。
yozakura10

2020/10/26 11:22

非ログイン時での各プロトタイプタイトルを押したらActionController::UrlGenerationError in Prototypes#show Showing /Users/kamiyaryota/Desktop/projects/protospace-31035/app/views/prototypes/show.html.erb where line #55 raised: No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id] Extracted source (around line #55): 53 54 55 56 57 58 <% @comments.each do |comment| %> <li class="comments_list"> <%= link_to comment.text + " (#{@prototype.user.name})", user_path(current_user), class: :comment_user %>  <% end %> <% end %> </li> というエラーが出たのですがこれのことでしょうか、これのことでしたら本文に記載いたします ローカル環境の非ログイン時に出ました routuesは追加いたしました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問