October 2019
Intermediate to advanced
358 pages
8h 22m
English
Our generated video controller gave us the CRUD basics, but as with any generated code, we’re going to need to tailor it to our needs. We want to link videos with users for this social platform. To do so, we need to grab the current user from the connection and scope our operations against the user. Open up your lib/rumbl_web/controllers/video_controller.ex, and scroll to the create action:
| | def create(conn, %{"video" => video_params}) do |
| | case Multimedia.create_video(video_params) do |
| | {:ok, video} -> |
| | conn |
| | |> put_flash(:info, "Video created successfully.") |
| | |> redirect(to: Routes.video_path(conn, :show, video)) |
| | |
| | {:error, %Ecto.Changeset{} = changeset} -> |
| | render(conn, "new.html" |
Read now
Unlock full access