diff --git a/app/api/mobile/apis/comments.rb b/app/api/mobile/apis/comments.rb index 75932d60f..2e84fe5a9 100644 --- a/app/api/mobile/apis/comments.rb +++ b/app/api/mobile/apis/comments.rb @@ -2,6 +2,7 @@ module Mobile module Apis class Comments < Grape::API + include ApplicationHelper resource :comments do desc '课程通知评论' params do @@ -82,8 +83,8 @@ module Mobile memo: {:subject => params[:subject],:content => '该贴来自手机App意见反馈'}, } cs = CommentService.new - memo = cs.create_feedback cs_params, current_user - raise "commit failed #{memo.errors.full_messages}" if memo.new_record? + memo,message = cs.create_feedback cs_params, current_user + raise message if memo.new_record? present :status, 0 end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 2f7092d9a..64157ea42 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -20,7 +20,7 @@ class ForumsController < ApplicationController #@memo.author_id = User.current.id #@forum = @memo.forum cs = CommentService.new - @memo = cs.create_feedback params,User.current + @memo,message = cs.create_feedback params,User.current respond_to do |format| if !@memo.new_record? format.html { redirect_to forum_path(@memo.forum) } diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index c865a500b..afdc306a4 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -60,4 +60,8 @@ module ApiHelper end [count,is_teacher] end + + def get_user_language user + (user.language.nil? || user.language == "") ? 'zh':user.language + end end \ No newline at end of file diff --git a/app/services/comment_service.rb b/app/services/comment_service.rb index e74cc902b..f75e14b85 100644 --- a/app/services/comment_service.rb +++ b/app/services/comment_service.rb @@ -1,4 +1,6 @@ class CommentService + include ApiHelper + include Redmine::I18n #评论 def news_comments params,current_user @news = News.find(params[:id]) @@ -84,7 +86,8 @@ class CommentService @memo.forum_id = "1" @memo.author_id = current_user.id @memo.save - @memo + message = "#{l(:label_commit_failed,:locale => get_user_language(current_user))}: #{@memo.errors.full_messages}" if @memo.new_record? + [@memo,message] end #课程留言列表 diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 4512344ad..c689d699d 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -346,7 +346,7 @@ class CoursesService membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user)) end if membership.nil? || membership.count == 0 - raise l(:label_no_courses,:locale => current_user.language.nil? ? 'zh':current_user.language) + raise l(:label_no_courses,:locale => get_user_language(current_user)) end membership.sort! {|older, newer| newer.created_on <=> older.created_on } result = [] @@ -355,19 +355,19 @@ class CoursesService latest_course_dynamics = [] latest_news = course.news.order("created_on desc").first unless latest_news.nil? - latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => l(:label_recently_updated_notification,:locale => get_user_language(current_user))} end latest_message = course.journals_for_messages.order("created_on desc").first unless latest_message.nil? - latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => l(:label_recently_updated_message,:locale => get_user_language(current_user))} end latest_attachment = course.attachments.order("created_on desc").first unless latest_attachment.nil? - latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => l(:label_recently_updated_courseware,:locale => get_user_language(current_user))} end latest_bid = course.homeworks.order('updated_on DESC').first unless latest_bid.nil? - latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => get_user_language(current_user))} end #每个作业中的最新留言 messages = [] @@ -382,7 +382,7 @@ class CoursesService end latest_bid_message = messages.first unless latest_bid_message.nil? - latest_course_dynamics << {:type => 4,:time => latest_bid_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 4,:time => latest_bid_message.created_on,:message => l(:label_recently_updated_message,:locale => get_user_language(current_user))} end #每个作业中学生最后提交的作业 homeworks = [] @@ -397,7 +397,7 @@ class CoursesService end latest_homework_attach = homeworks.first unless latest_homework_attach.nil? - latest_course_dynamics << {:type => 4,:time => latest_homework_attach.updated_at,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 4,:time => latest_homework_attach.updated_at,:message => l(:label_recently_updated_homework,:locale => get_user_language(current_user))} end latest_course_dynamics.sort!{|order,newer| newer[:time] <=> order[:time]} latest_course_dynamic = latest_course_dynamics.first diff --git a/config/locales/en.yml b/config/locales/en.yml index e84a26815..33e4da965 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1588,3 +1588,5 @@ en: label_recently_updated_message: Recently updated the message label_recently_updated_courseware: Recently updated the courseware label_no_courses: You do not participate in any course, please search the curriculum, course, or create a course! + label_commit_failed: commit failed + #api end \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index dc1937926..5628598cc 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2032,6 +2032,9 @@ zh: label_recently_updated_message: 最近更新了留言 label_recently_updated_courseware: 最近更新了课件 label_no_courses: 您没有参与任何课程,请搜索课程、加入课程,或者创建课程吧! + label_commit_failed: 提交失败 + #api end + label_end_time: 截止时间 label_send_email: 确定发送 label_input_email: 请输入邮箱地址