mardi 25 août 2015

How to link my courses/show.html.erb to the current_course?

I'm creating an app that allows users to access different courses on video (each course has its own 4 or 5 videos, and each video has its own page).

I created a courses_controller which allows me to index and show the courses stored in the database.

Courses_controller.rb :

class CoursesController < ApplicationController
before_action :set_course, only: [:show]
skip_before_filter  :verify_authenticity_token
before_filter :authorize , except: [:index, :show]

def index
    @courses = Course.all
end

def show
end

private
# Use callbacks to share common setup or constraints between actions.
def set_course
    @course = Course.find(params[:id])
end

def authorize
    unless User.find_by_id(session[:user_id]) and User.find_by_id(session[:user_id]).active == true
        redirect_to subscriptions_path, :notice => "Vous devez souscrire à un abonnement pour avoir accès a cette page"
    end
end

Each course is stored in a seeds.rb file.

courses/index.html.erb lists the courses, courses/show.html.erb shows the presentation of a specific course.

How to create a link to the current course from the show.html.erb page? I thought about add a link for each course in the seeds, but it don't look possible.

Any idea?

Aucun commentaire:

Enregistrer un commentaire