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" %>