From eed8f4845fe91c7bcf989ae8237b793a5219eddb Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 13 Jul 2017 10:16:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AE=9E=E8=AE=AD=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 40 +++++++++++++++---- app/helpers/application_helper.rb | 4 ++ app/views/layouts/base_subject.html.erb | 0 app/views/shixuns/index.html.erb | 2 +- app/views/subjects/_choose_shixun.html.erb | 8 ++-- app/views/subjects/index.html.erb | 2 +- ...eate_subject.js.erb => new_subject.js.erb} | 2 +- app/views/subjects/show.html.erb | 0 public/stylesheets/css/edu-subject.css | 7 +++- 9 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 app/views/layouts/base_subject.html.erb rename app/views/subjects/{create_subject.js.erb => new_subject.js.erb} (80%) create mode 100644 app/views/subjects/show.html.erb diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index b1b60fb0c..21655129d 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -1,4 +1,10 @@ class SubjectsController < ApplicationController + layout 'base_subject' + before_filter :require_login + before_filter :check_authentication + before_filter :find_subject, :except => [:index, :create_subject, :new_subject, :index, :search, :shixun_courses] + + include ApplicationHelper def index @order = params[:order] || "created_at" @@ -15,20 +21,38 @@ class SubjectsController < ApplicationController render :layout => "base_edu" end - def create_subject + def show + + end + + def new_subject if Shixun.where(:user_id => User.current.id).count > 0 @status = 1 @course_lists = CourseList.where(:id => ShixunMajorCourse.where(:shixun_id => Shixun.where(:user_id => User.current.id).map(&:id)).map(&:course_list_id)) else @status = 0 end - end - - def new_subject - if params[:course_list_id] - course = CourseList.find params[:course_list_id] - - #Subject.create(:name => ) + respond_to do |format| + format.js end end + + def create_subject + if params[:course_list_id] + course = CourseList.find params[:course_list_id] + if course + subject = Subject.create(:name => course.name, :user_id => User.current.id, :visits => 0, :status => 0, :course_list_id => course.id) + end + end + redirect_to subject_path(subject) + end + + private + # Find subject of id params[:id] + def find_subject + @subject = Subject.find_by_id(params[:id]) + render_404 if @subject.nil? + rescue ActiveRecord::RecordNotFound + render_404 + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8f33079fb..578a1091f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1925,6 +1925,10 @@ module ApplicationHelper title << ("我的实训") elsif params[:controller] == "shixuns" && params[:action] == "index" title << ("项目实训") + elsif @subject + title << (@subject.name.nil? ? "课程实训" : @subject.name) + elsif params[:controller] == "subjects" && params[:action] == "index" + title << ("课程实训") elsif @organization title << (@organization.name.nil? ? "创新源于实践" : @organization.name) elsif @forum || params[:controller] == "forums" diff --git a/app/views/layouts/base_subject.html.erb b/app/views/layouts/base_subject.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/shixuns/index.html.erb b/app/views/shixuns/index.html.erb index cafcd9d63..f232af94d 100644 --- a/app/views/shixuns/index.html.erb +++ b/app/views/shixuns/index.html.erb @@ -2,7 +2,7 @@

项目实训

- <%= link_to "创建", create_subject_subjects_path(), :remote => true, :class => "task-btn task-btn-green fr mt6" %> + <%= link_to "创建", new_shixun_path, :class => "task-btn task-btn-green fr mt6" %>

请至少选择一个课程

  • - 确定 + 确定 取消
  • @@ -34,7 +34,7 @@ $("#lessong_nonechecked_tip").show(); } else{ $.ajax({ - url: '<%= new_subject_subjects_path() %>', + url: '<%= create_subject_subjects_path() %>', data: {course_list_id: $("input[name='course_list_id']:checked").val()}, remote: true, success: function(data){ diff --git a/app/views/subjects/index.html.erb b/app/views/subjects/index.html.erb index 193588770..61b783ee8 100644 --- a/app/views/subjects/index.html.erb +++ b/app/views/subjects/index.html.erb @@ -3,7 +3,7 @@

    课程实训

    - <%= link_to "新建", new_course_path, :class => "task-btn task-btn-green fr mt6" %> + <%= link_to "新建", new_subject_subjects_path, :remote => true, :class => "task-btn task-btn-green fr mt6" %>