Skip to content

Instantly share code, notes, and snippets.

@jetrubyshared
Created July 11, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jetrubyshared/9960c2280a14ff2acf0cdf9e4bf3fade to your computer and use it in GitHub Desktop.
Save jetrubyshared/9960c2280a14ff2acf0cdf9e4bf3fade to your computer and use it in GitHub Desktop.
###############
## WRONG ##
###############
class Users::CoursesController
def edit
@course = Course.find(params[:id])
end
end
class Users::LessonsController
def new
@lesson = Lesson.new(lesson_params)
end
end
###############
## RIGHT ##
###############
class Users::CoursesController
def edit
@course = current_user.courses.find(params[:id])
end
end
class Users::LessonsController
def new
course = current_user.courses.find(params[:course_id])
@lesson = course.lessons.build(lesson_params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment