Problem with Association II, Part 5


#1

I have finished the entire exercise, all the check-marks are off.

Though when I click “Learn more” like the last check-mark says, it goes to: http://localhost:3000/movies/%23<Movie::ActiveRecord_Relation:0x5432040>

and shows error

def show
    @movie = Movie.find(params[:id])
    @actors = @movie.actors.all
  end

I am wondering what I done wrong? I apparently passed all the test, but it doesn’t work?

Here are my files:

route.rb:

Rails.application.routes.draw do

 get '/movies' => 'movies#index'
 get 'movies/:id' => 'movies#show', as: :movie
end

movies_controller.rb

class MoviesController < ApplicationController

  def index
    @movies = Movie.all
  end

  def show
    @movie = Movie.find(params[:id])
    @actors = @movie.actors.all
  end

end

index.html.erb

<div class="hero">
  <div class="container">
    <h2>Interstellar</h2>
    <p>Former NASA pilot Cooper (Matthew McConaughey) and a team of researchers travel across the galaxy to find out which of three planets could be mankind's new home.</p>
    <%= link_to "Learn more", movie_path(@movies) %>
  </div>
</div>

<div class="main">
  <div class="container">
  <h2>Popular Films</h2>


    <% @movies.each do |m| %>
    <div class="movie">
    <%= image_tag m.image %>
      <h3> <%= m.title %> </h3>
      <p> <%= m.release_year %> </p>
    </div>
<% end %>

  </div>
</div>

show.html.erb

<div class="main movie-show">
  <div class="container">
    <div class="movie">

      <div class="info">
          <!-- movie image -->
          <%= image_tag @movie.image %>
          <h3 class="movie-title"><%= @movie.title %>   </h3>
          <p class="movie-release-year"> <%= @movie.release_year %> </p>
          <p class="movie-plot"> <%= @movie.plot %> </p>
        </div>
      </div>

      <h2>Cast</h2>
       <% @actors.each do |a| %>

      <div class="actor">

        <%= image_tag a.image %>
        <h3 class="actor-name"> <%= a.first_name %> <%= a.last_name %> </h3>
        <p class="actor-bio"><%= a.bio %>  </p>
      </div>
 <% end %>
  </div>
</div>


#2

Also, the browser for whatever reason doesn’t work after I am so far in each of these challenges. So I have to reference with my own work that I’m doing on my own PC and how it works from there. Luckily I copy all the data over and run rails and that works, but it’s complicated when I’m trying to see what’s wrong specifically on CodeAcademy.


#3

Is there a way to restart the virtual machine? Becuase I think that’s where the problem is.


#4

Also, is there a way to cancel all the work you’ve done on a specific project on here and restart from the beginning? As far as I can tell, you can only review the work that you’ve already done.


#5

@kvy

is there a way to cancel all the work you’ve done on a specific project on here and restart from the beginning?

Yes, it’s under the “Get Help” menu in the lower-right.


#6

Try removing the .all from @actors = @movie.actors.all. Also, it looks like you are missing a closing div tag in the movie show file.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.