"Next" button creates a Viewed_Lesson | Ruby on Rails 4 | Learning App -


i trying make "next" button should generate viewed_lesson (user_id, lesson_id, boolean: true) , redirect next lesson. purpose make tracking progress show progress of user on course.

my models:

class course     has_many :lessons end  class lesson   #fields: course_id   belongs_to :course end class user   has_many :viewed_lessons   has_many :viewed_courses end class viewedlesson   #fields: user_id, lesson_id, completed(boolean)     belongs_to :user   belongs_to :lesson end class viewedcourse   #fields: user_id, course_id, completed(boolean)     belongs_to :user   belongs_to :course   end 

what create action of viewed_lesson controller should like?

there create method needed. , how button/form in view? button placed in lectures/id/lesson/id

thank in advance!

it should following:

class viewedlessonscontroller < applicationcontroller   before_filter :set_user_and_lesson   def create     @viewed_lesson = viewlession.new(user_id: @user.id, lession_id: @lesson.id, completed: true)     if @viewed_lesson.save       # redirect_to appropriate location     else       # take appropriate action     end   end end 

in applicationcontroller class, can do:

def set_user_and_lesson   @user = user.find_by_id(params[:user_id])   @lesson = lesson.find_by_id(params[:lesson_id]) end 

you need define routes it, , remember, need have models viewedlesson , viewedcourse.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -