Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Cleaning Up Our Code

kabir k
PLUS
kabir k
Courses 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

before_action :find_todo_list 

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?

1 Answer

Philip Bessa
Philip Bessa
5,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.

kabir k
kabir k
Courses Plus Student 18,036 Points

Right, so much for cleaning up lol

Anyway.....thanks, Philip.