From ac82910aa5f30c6084270b75d8df2cf04cb033a3 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 29 Oct 2015 11:53:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E7=BA=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 21 +++++++++++++++ app/models/blog_comment.rb | 9 +++++++ .../courses/_course_outlines_list.html.erb | 27 +++++++++++-------- app/views/courses/course_outline.js.erb | 2 +- app/views/courses/set_course_outline.js.erb | 1 + app/views/layouts/base_courses.html.erb | 27 ++++++++++++++++--- config/routes.rb | 1 + 7 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 app/views/courses/set_course_outline.js.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1113de159..1216599a1 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -713,7 +713,28 @@ class CoursesController < ApplicationController #从课程创建的老师那里选择课程大纲 def course_outline + @teacher = User.find(@course.tea_id) + @blog_articles = @teacher.blog.articles + respond_to do |format| + format.js + end + end + #根据关键字搜索,查找方法一样的,但返回内容不一样 + def search_course_outline + @article_title = params[:title] + @teacher = User.find(@course.tea_id) + @blog_articles = @teacher.blog.articles.like(@article_title) + render :json=>@blog_articles.to_json + end + + #设置或者更改课程的大纲 + def set_course_outline + @course.outline = params[:outline_id] + @course.save + respond_to do |format| + format.js + end end #删除课程 diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 9bb28ddd8..27da33121 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -19,6 +19,15 @@ class BlogComment < ActiveRecord::Base after_save :add_user_activity before_destroy :destroy_user_activity + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where(" LOWER(title) LIKE :p ", :p => pattern) + end + } + #在个人动态里面增加当前动态 def add_user_activity if self.parent_id.nil? #只有发博文才插入动态 diff --git a/app/views/courses/_course_outlines_list.html.erb b/app/views/courses/_course_outlines_list.html.erb index cb7c52cfb..b8a8bfd2a 100644 --- a/app/views/courses/_course_outlines_list.html.erb +++ b/app/views/courses/_course_outlines_list.html.erb @@ -8,19 +8,24 @@ -
+ + <%= form_tag(url_for(:controller=>'courses',:action=>'set_course_outline',:id=>course.id),:method=>'post',:remote=>'true') do %>