5.4 Movies || using link_to in order to add path to specific movie


#1

Hi,
I’m trying to go through step 5.4 where we are about to just add line to link specific movie from index view with designed view created on show.erb.html template.

I am constantly getting this error: Did you add link for movie?
when my code in index.erb.html file looks like:

    <% @movies.each do |m| %>
      
/>

<%= m.title %>

<%= m.release_year %>

<%= m.plot %>

<%= link_to 'Learn more', movie_path(m) %>
<% end %>

Movies controller has following code:

class MoviesController < ApplicationController
	def index
		@movies = Movie.all
	end
  
  def show
    	@movie = Movie.find(params[:id])
    	@actors = @movie.actors.all
  end
  
  private
  def movie_params
      params.required(:movie).permit(:id)
  end
end

and routes.rb also looks fine for me:

Rails.application.routes.draw do

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

Does anyone see what I did wrong or why am I getting this kind of error message?


#2

Hi @witekm,

Try using double quotes (") around Learn more, like this:

<%= link_to "Learn more", movie_path(m) %>

It shouldn’t cause a difference, but sometimes Codecademy’s code checker will be too thorough in making sure your code exactly matches what they want.


#3

@zystvan many thanks, that change made a difference and code is working fine right now.


#4

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