開発中にこのエラー メッセージが表示される理由がわかりません。なぜなら、このエラー メッセージは 1 分前に機能していたからで、まだ実稼働環境で機能しているためです。
すべての関連付けはそのままです。このメッセージがどこから来たのかわかりませんか? どうしたの?
エラーメッセージは次のとおりです。
NoMethodError in Comments#index
Showing /Users/apane/Downloads/leap_stage/leap_stage/app/views/comments/index.html.erb
undefined method `title' for nil:NilClass
   <span class="title">
   <li>comment by: <strong><%= comment.author_name %></strong></span>
   <%= time_ago_in_words(comment.created_at) + " ago" %> | on <%= link_to comment.song.title, comment.song %></span>
    <br />
    <%= comment.content %><br></li>
    <hr>
コメント#index.html.erb
<div id="layout-1">
<!--div class="left-side"> -->
<%#= will_paginate @songs %>
<h6>Latest comments</h6>
<hr>
<ul><% @comments.each do |comment| %>
<span class="title">
<li>comment by: <strong><%= comment.author_name %></strong></span>
<%= time_ago_in_words(comment.created_at) + " ago" %> | on <%= link_to comment.song.title, comment.song %></span>
    <br />
 <%= comment.content %><br></li>
    <hr>
 <%#=link_to '▼'.html_safe, vote_against_song_path(song), :remote => true, :method => :put %> 
<%#= link_to 'Show', song, class: "button small secondary" %>
<%= link_to('Edit', edit_comment_path(comment), class: "button small secondary") if can? :update, comment %>
<%= link_to('Destroy', comment, method: :delete, data: {confirm: 'Are you sure?'}, class: "button small secondary") if can? :destroy, comment %>
<% end %>
</ol>
</div>
コメント_コントローラー.rb
class CommentsController < ApplicationController
  before_action :set_comment, only: [:show, :edit, :update, :destroy]
  def index
    @comments = Comment.all
  end
  def show
  end
  # GET /comments/new
  def new
  end
  # GET /comments/1/edit
  def edit
  end
  # POST /comments
  # POST /comments.json
  def create
    @comment = Comment.new(comment_params)
    respond_to do |format|
      if @comment.save
        format.html { redirect_to song_url(@comment.song_id), notice: 'Comment was successfully created.'  }
        format.json { render action: 'show', status: :created, location: @comment}
      else
        format.html { render action: 'new' }
        format.json { render json: @comment.errors, status: :unprocessable_entity }
      end
    end
  end
  # PATCH/PUT /comments/1
  # PATCH/PUT /comments/1.json
  def update
    respond_to do |format|
      if @comment.update(comment_params)
        format.html { redirect_to song_url(@comment.song_id), notice: 'Comment was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @comment.errors, status: :unprocessable_entity }
      end
    end
  end
  # DELETE /comments/1
  # DELETE /comments/1.json
  def destroy
    @comment.destroy
      redirect_to song_url(@comment.song_id)
    end
  private
    # Use callbacks to share common setup or constraints between actions.
    def set_comment
      @comment = Comment.find(params[:id])
    end
    # Never trust parameters from the scary internet, only allow the white list through.
    def comment_params
      params.require(:comment).permit(:song_id, :author_name, :site_url, :content, :user_id)
    end
end