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 %>
- -
发布时间:2015-05-11
- + <% unless articles.blank? %> + <% articles.each do |article|%> + +
发布时间:<%= format_date(article.created_at)%>
+ <% end %> + <% end %>
-
确定
-
取消
+
确定
+
取消
+<% end %> diff --git a/app/views/courses/course_outline.js.erb b/app/views/courses/course_outline.js.erb index 300ba6466..f747661b8 100644 --- a/app/views/courses/course_outline.js.erb +++ b/app/views/courses/course_outline.js.erb @@ -1,4 +1,4 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'course_outlines_list') %>'); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'course_outlines_list',:locals => {:articles=>@blog_articles,:course=>@course}) %>'); showModal('ajax-modal', '300px'); //$('#ajax-modal').css('height','250px'); $('#ajax-modal').css('padding-top','0px'); diff --git a/app/views/courses/set_course_outline.js.erb b/app/views/courses/set_course_outline.js.erb new file mode 100644 index 000000000..ad3b78189 --- /dev/null +++ b/app/views/courses/set_course_outline.js.erb @@ -0,0 +1 @@ +hideModal(); \ No newline at end of file diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 4e9868efe..43f754097 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -63,7 +63,7 @@ <%= l(:field_is_private)%> <% end %> - <%if @course.tea_id == User.current.id && @course.outline == 0%> + <%if @course.tea_id == User.current.id %> 设置大纲 @@ -172,6 +172,7 @@ <%= call_hook :view_layouts_base_body_bottom %>