kabir kCourses Plus Student 18,036 Points
Code repeated inside the TodoItems Controller in the Teacher's Notes
In the Teacher's Notes of the "Cleaning Up Our Code" video, the code
is written twice on the same line in this code
class TodoItemsController < ApplicationController before_action :find_todo_list before_action :find_todo_list ... def find_todo_list @todo_list = TodoList.find(params[:todo_list_id]) end
Is that an error or not? And what does the code do?
Philip Bessa5,396 Points
It shouldn't be written twice. It's just another problem among a litany of others in this course. So much for cleaning it up, eh? LOL
before_action basically means what it says: before any method (or action) in the Items Controller, it executes the method
find_todo_list first. So if it runs the
create method, it first runs the
find_todo_list method first. If it runs the
update method, it runs
find_todo_list first as well. So instead of repeating the same line of code it's just said once, with the same result.