rails - watch list day2

Minsoo·2022년 3월 24일
0

rails

목록 보기
4/4

1. controller setup


먼저 이해를 위한 스키마 사진 재업로드

🏝 key point

  1. 어떤 모델의 컨트롤러가 필요한지 생각해보기.
    no need to generate movie controller
    왜냐하면 먼저 movie 정보들을 모두 api로 가져와 필요한 정보를 저장하기 위해서는 모델이 필요하지만, 각각의 movie는 데이터일뿐 이를 생성하고 지우고 수정하는 등 crud 액션이 필요 없다 .

  2. 따라서 list / bookmark controller만 생성.

* list controller

  • show
    @bookmark = Bookmark.new 생성 (왜? 이해안된다..)
  • find_list
    show, destroy 액션은 먼저 정확한 리스트를 찾아야params값을 얻을 수 있기 때문에,(show와 destroy는 id-params값을 알아야하기 때문에) 먼저 리스트를 찾아준다. 이 때 찾는 메소드는 private 메소드로 빼준다.

* bookmark controller

set_list
when bookmark request new and create action, have to make sure where the bookmark should be belongs to. to do that,

  private
  before_action :set_list, only: [:new, :create]
	def set_list
    	@list = List.find(params[:list_id])
  	end

when bookmark created ,
Assign the list to the bookmark.

 @bookmark.list = @list

profile
Hello all 👋🏻 📍London

0개의 댓글