From 99686ec26974e0cf14af376b03eec8520f809436 Mon Sep 17 00:00:00 2001 From: yanxd Date: Sat, 21 Dec 2013 10:15:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=99=E8=A8=80=E4=B8=8D=E8=83=BD=E6=98=AF?= =?UTF-8?q?=E7=A9=BA=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- app/controllers/words_controller.rb | 10 ++++++++-- app/models/journals_for_message.rb | 2 +- app/models/project.rb | 10 ++++++++-- app/views/projects/feedback.html.erb | 1 - config/locales/zh.yml | 2 ++ 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b5b0bdb5..2c220c25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -630,7 +630,7 @@ class ApplicationController < ActionController::Base obj[@obj_pages.offset, @obj_pages.per_page] else logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}" - nil + raise RuntimeError, 'unknow type, Please input you type into this helper.' end end end diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index b6e24473..113adecc 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -129,8 +129,14 @@ class WordsController < ApplicationController def leave_project_message user = User.current message = params[:new_form][:project_message] - Project.add_new_jour(user, message, params[:id]) - redirect_to project_feedback_path(params[:id]) + feedback = Project.add_new_jour(user, message, params[:id]) + if(feedback.errors.empty?) + redirect_to project_feedback_path(params[:id]), notice: l(:label_feedback_success) + else + flash[:error] = feedback.errors.full_messages[0] + redirect_to project_feedback_path(params[:id]) + end + end def add_brief_introdution diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 74e96094..bb03ad12 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -2,7 +2,7 @@ class JournalsForMessage < ActiveRecord::Base attr_accessible :jour_id, :jour_type, :notes, :reply_id, :status, :user_id attr_accessor :indice - + validates :notes, presence: true belongs_to :jour, :polymorphic => true belongs_to :user has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy diff --git a/app/models/project.rb b/app/models/project.rb index cafdd958..d198d38c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -160,12 +160,18 @@ class Project < ActiveRecord::Base # 项目留言 added by fq def self.add_jour(user, notes) project = Project.find('trustie') - project.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => 0) + # project.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => 0) + pjfm = project.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + pjfm.save + pjfm end def self.add_new_jour(user, notes, id) project = Project.find(id) - project.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => 0) + # project.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => 0) + pjfm = project.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + pjfm.save + pjfm end # end diff --git a/app/views/projects/feedback.html.erb b/app/views/projects/feedback.html.erb index 416ee897..be7827e9 100644 --- a/app/views/projects/feedback.html.erb +++ b/app/views/projects/feedback.html.erb @@ -1,6 +1,5 @@

<%= l(:label_user_response) %>

-<%= render_flash_messages %> <%= form_for('new_form', :method => :post, :url => {:controller => 'words', :action => 'leave_project_message'}) do |f|%> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 6f6d1939..b072a342 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -847,6 +847,8 @@ zh: label_user_commits: "代码提交" label_user_watchered: "关注" # huang添加的 label_user_newfeedback: "留言" ## huang添加的 + label_feedback_success: "留言成功" + label_feedback_fail: "留言失败" label_user_login: "最后登录" label_user_mail: "邮件地址" label_user_joinin: "加入时间"