My models
class Course
has_many :lessons, through: :chapters
end
class Lesson
belongs_to :chapter
has_one :course, through: :chapter
end
class User
has_many :user_lessons
end
class UserLesson
#fields: user_id, lesson_id, completed(boolean)
belongs_to :user
belongs_to :lesson
end
class Chapter
has_many :lessons
belongs_to :course
end
My UserLesson Controller:
class UserLessonsController < ApplicationController
before_filter :set_user_and_lesson
def create
@user_lesson = UserLession.create(user_id: @user.id, lession_id: @lesson.id, completed: true)
if @user_lesson.save
# redirect_to Course show action///// How can I redirect to that?
else
# take the appropriate action
end
end
end
Basically what I want to to is to redirect_to the show action of the Course that has the lesson? (it is basically a go back to the whole list of lessons. Lessons are nested within Course) The problem is that could not find lecture id.
No route matches {:action=>"show", :controller=>"lectures", :id=>nil} missing required keys: [:id]
Routes.rb
resources :courses do
resources :lessons
end
resources :user_lessons
Links that send the data to create method
<%= link_to 'Back to Lesson list', user_lessons_path(@user_lesson, user_lesson: {user_id: 'current_user.id', lesson_id: 'lesson.id'}), :method => :post, data: {confirm: 'are you sure?'} %>