留言不能是空字符

This commit is contained in:
yanxd 2013-12-21 10:15:41 +08:00
parent 775f07a89d
commit 99686ec269
6 changed files with 20 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,5 @@
<!-- fq -->
<h3><%= l(:label_user_response) %></h3>
<%= render_flash_messages %>
<%= form_for('new_form', :method => :post,
:url => {:controller => 'words', :action => 'leave_project_message'}) do |f|%>

View File

@ -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: "加入时间"