lessons functionality

This commit is contained in:
Adrian Hinz 2019-05-16 10:58:43 +02:00
parent b30739c21a
commit 4d8a5138f2
6 changed files with 5 additions and 6 deletions

View File

@ -28,6 +28,7 @@ module Admin
def create def create
@lesson = Lesson.new(admin_lesson_params) @lesson = Lesson.new(admin_lesson_params)
@week = @lesson.week @week = @lesson.week
@lesson.course = @week.course
params[:week_id] = @week.id params[:week_id] = @week.id
respond_to do |format| respond_to do |format|
if @lesson.save if @lesson.save

View File

@ -23,12 +23,8 @@ class Lesson < ApplicationRecord
scope :name_desc, -> { order(name: :desc) } scope :name_desc, -> { order(name: :desc) }
# == Callbacks ============================================================ # == Callbacks ============================================================
before_create :b_create
# == Class Methods ======================================================== # == Class Methods ========================================================
# == Instance Methods ===================================================== # == Instance Methods =====================================================
def b_create
self.course = week.course
end
end end

View File

@ -17,7 +17,7 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<%= form.label :video %> <%= form.label :video %>
<%= f.select :video_id, options_for_select(Video.all.map{|s|[s.name, s.id]}) %> <%= form.select :video_id, options_for_select(Video.all.map{|s|[s.name, s.id]}, selected: @lesson.video_id), { include_blank: true }, { class: 'form-control' } %>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">

View File

@ -4,7 +4,7 @@
<div class="card shadow mb-4"> <div class="card shadow mb-4">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-primary"><%= t('lesson.list') %></h6> <h6 class="m-0 font-weight-bold text-primary"><%= t('lesson.list') %></h6>
<%= link_to raw('<i class="fa fa-plus"></i> Dodaj Nowy Tydzien'), new_admin_lesson_path(week_id: @week.id), { remote: true, class: 'btn btn-sm btn-primary float-right' } %> <%= link_to raw("<i class=\"fa fa-plus\"></i> #{t('lesson.add_new')}"), new_admin_lesson_path(week_id: @week.id), { remote: true, class: 'btn btn-sm btn-primary float-right' } %>
</div> </div>
<div class="card-body"> <div class="card-body">
<div id="ajax_form"></div> <div id="ajax_form"></div>

View File

@ -1,3 +1,4 @@
<h1 class="h3 mb-1 text-gray-800"><%= t('course.title_show') %>: <strong><%= @course.name %></strong></h1> <h1 class="h3 mb-1 text-gray-800"><%= t('course.title_show') %>: <strong><%= @course.name %></strong></h1>
<h1 class="h3 mb-1 text-gray-800"><%= t('week.title_show') %>: <strong><%= @week.name %></strong> (<%= link_to raw(t('back')), admin_course_path(@course) %>)</h1> <h1 class="h3 mb-1 text-gray-800"><%= t('week.title_show') %>: <strong><%= @week.name %></strong> (<%= link_to raw(t('back')), admin_course_path(@course) %>)</h1>
<p class="mb-4"><%= @week.description %></p> <p class="mb-4"><%= @week.description %></p>
<%= render partial: '/admin/lessons/partials/index' %>

View File

@ -19,6 +19,7 @@ pl:
name: 'Nazwa' name: 'Nazwa'
description: 'Opis' description: 'Opis'
course: 'Kurs' course: 'Kurs'
video: Plik Wideo
week: 'Tydzień' week: 'Tydzień'
informations: 'Dodatkowe Informacje' informations: 'Dodatkowe Informacje'
file: 'Plik' file: 'Plik'