title: Rails app - extra record displaying
body: <p>I have an app that allows users to add albums they like to a database. Anyone can then come along and write a review for that album. Pretty simple. </p>
  
  <p>I am running into a problem where an extra record appears to be created for the reviews on each album's show page. Every album, even if it has not ever been reviewed, has an additional, seemingly empty review being displayed when I use .each to display each review in the album show page. I want to get rid of that. </p>
  
  <p>Here is an image of the problem. I have used CSS to highlight reviews in red. As you can see, there is an empty review at the bottom. When I inspect the review in question, it's raty title is "Not reviewed yet!"</p>
  
  <p><a href="https://i.stack.imgur.com/kWTMh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kWTMh.png" alt="enter image description here"></a></p>
  
  <p>Here is my albums_controller:</p>
  
  <pre><code>class AlbumsController &lt; ApplicationController
    before_action :set_album, only: [:show, :edit, :update, :destroy]
    before_action :authenticate_user!, only: [:edit, :new, :update, :destroy]
  
    def index
      @albums = Album.all
      if params[:search].nil?
        @albums = Album.all.order(year: :desc).order(title: :asc).paginate(:page =&gt; params[:page], :per_page =&gt; 24)
      else
        @albums = @albums.where("albums.title || albums.year || albums.artist LIKE ?", "%#{params[:search]}%").order(year: :desc).order(title: :asc).paginate(:page =&gt; params[:page], :per_page =&gt; 24)
      end
    end
  
    def show
       if @album.reviews.blank?
        @average_review = 0
       else
        @average_review = @album.reviews.average(:rating).round(2)
       end
       @review = @album.reviews.build
     end
  
     def new
       @album = Album.new
     end
  
     def edit
  
     end
  
     def create
       @album = current_user.albums.build(album_params)
  
       respond_to do |format|
        if @album.save
           format.html { redirect_to @album, notice: 'Album was successfully created.' }
          format.json { render :show, status: :created, location: @album }
        else
          format.html { render :new }
          format.json { render json: @album.errors, status: :unprocessable_entity }
        end
      end
    end
  
    def update
       respond_to do |format|
        if @album.update(album_params)
          format.html { redirect_to @album, notice: 'Album was successfully updated.' }
          format.json { render :show, status: :ok, location: @album }
        else
          format.html { render :edit }
          format.json { render json: @album.errors, status: :unprocessable_entity }
        end
      end
    end
  
    def destroy
      @album.destroy
      respond_to do |format|
        format.html { redirect_to albums_url, notice: 'Album was successfully    destroyed.' }
        format.json { head :no_content }
      end
    end
  
  private
  # Use callbacks to share common setup or constraints between actions.
  
  def set_album
    @album = Album.find(params[:id])
  end
  
  def album_params
    params.require(:album).permit(:title, :artist, :year, :cover)
  end
  end
  </code></pre>
  
  <p>Here is the album show page, which is where the extra review is being displayed:</p>
  
  <pre><code>&lt;div class="row"&gt;
  &lt;div class="col-xs-10 col-md-6 col-md-push-3 col-xs-push-1 top bottom"&gt;
      &lt;%= image_tag @album.cover, class: 'show_image' %&gt;
      &lt;h2&gt;&lt;%= @album.title %&gt;&lt;/h2&gt;
      &lt;h4&gt;&lt;%= @album.artist %&gt;&lt;/h4&gt;
      &lt;h5&gt;&lt;%= @album.year %&gt;&lt;/h5&gt;
      &lt;p class="white"&gt;Average Review&lt;div class="average-review-rating" data-score=&lt;%= @average_review %&gt;&gt;&lt;/div&gt;&lt;/p&gt;
      &lt;% if user_signed_in? %&gt;
          &lt;% if @album.user_id == current_user.id %&gt; 
              &lt;%= link_to 'Edit', edit_album_path(@album), class: 'grey' %&gt; 
              | &lt;%= link_to 'Delete', album_path, method: :delete, data: {confirm: "Are you sure?"}, class: 'grey' %&gt;
          &lt;% end %&gt; 
      &lt;% end %&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;h4&gt;Reviews&lt;/h4&gt;
      &lt;% if user_signed_in? %&gt;
          &lt;p class="grey"&gt;Write a review&lt;/p&gt; 
  
          &lt;%= form_for [@album, @review] do |r| %&gt;
              &lt;div class="form-group"&gt;
                  &lt;div id="rating-form"&gt;
                      &lt;label&gt;Rating&lt;/label&gt;
                  &lt;/div&gt;  
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;%= r.text_area :comment, class: 'form-control', placeholder: "Write a comment" %&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;%= r.submit "Create", class: 'btn btn-success' %&gt;
              &lt;/div&gt;
          &lt;% end %&gt; 
      &lt;% end %&gt; 
  
      &lt;br /&gt;
      &lt;% @album.reviews.each do |r| %&gt;
          &lt;div class="red"&gt;
              &lt;div class="review-rating" data-number="&lt;%= r.rating %&gt;"&gt;
              &lt;/div&gt;
              &lt;p class="white"&gt;&lt;%= r.comment %&gt;&lt;/p&gt;
              &lt;% if user_signed_in? %&gt;
                  &lt;% if current_user.id == r.user_id %&gt; 
                      &lt;%= link_to 'Edit', edit_album_review_path(@album, r.id), class: 'grey' %&gt; |
                      &lt;%= link_to 'Delete', album_review_path(@album, r.id), method: :delete, data: {confirm: "Are you sure?"}, class: 'grey' %&gt;
                  &lt;% end %&gt; 
              &lt;% end %&gt;
              &lt;br /&gt;&lt;br /&gt;
          &lt;/div&gt;
      &lt;% end %&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  
  &lt;script&gt; 
  $('.review-rating').raty({
  readOnly: true,
  score: function() {
      return $(this).attr('data-number');
  },
  path: '/assets/'
  });
  
  $('#rating-form').raty({
  path: '/assets/',
  scoreName: 'review[rating]'
  });
  
  $('.average-review-rating').raty({
  readOnly: true,
  path: '/assets/',
  score: function() {
      return $(this).attr('data-score')
  }
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Any help would be very appreciated!</p>