Home>

I am making a web application with rails.
I would like to make a long YouTube video with a separate page for each chapter.
Click on a thumbnail to access the playback page for that chapter.

Error message

When you hit the page in the format of "/ movies /: id/chapters /: id", you can jump to a page where only a part of a long movie can be played.
I would like to access the specified movie page by passing the argument to the "movie_chapter_path" presented in the helper method.

movie_chapter_path GET/movies /: movie_id/chapters /: id (.: format)
Applicable source code

▼/app/views/dashboard/index.html.haml

= render partial: 'layouts/movie-box', collection: @chapter, as: 'chapter'

▼/app/views/layouts/_movie-box.html.haml

% li.movie-box--list
  = link_to movie_chapter_path (movie, chapter) do
Since/app/views/dashboard/index.html.haml, the chapter id of the URL comes out without any problem,
The part where movie id is entered is output as "% 23% 3CMovie :: ActiveRecord_Relation: 0x00007ff2583d1308% 3E".
In other words, a URL like this has been displayed.
"/ Movies /% 23% 3CMovie :: ActiveRecord_Relation: 0x00007ff2583d1308% 3E/chapters/544"

I think it's because you didn't pass a movie argument,

= render partial: 'layouts/movie-box', collection: @chapter, as: 'chapter'


I can't tell if I can't search for this multiple specification method.
I want to know if you know anyone!

I searched, but I didn't get the information I wanted.

  • Answer # 1

    ▼/app/views/layouts/_movie-box.html.haml

    % li.movie-box--list
      = link_to movie_chapter_path (movie, chapter) do


    % li.movie-box--list
      = link_to movie_chapter_path (chapter.movie, chapter) do

    After making this correction, it appears!

Related articles