添加首页定制的非空验证,长度验证

This commit is contained in:
z9hang 2014-07-14 16:12:58 +08:00
parent 3aab1b172c
commit cf339edb6c
5 changed files with 34 additions and 67 deletions

View File

@ -246,19 +246,21 @@ class AdminController < ApplicationController
@first_page.title = params[:title]
if @first_page.save
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
format.html {
redirect_to admin_first_page_made_path
}
format.api { render_api_ok }
#format.json { render json: @first_page, status: :created, location: @first_page }
end
else
respond_to do |format|
flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}"
format.html {
first_page_made
render :action => 'first_page_made'
}
format.api { render_validation_errors(@first_page) }
#format.json { render json: @first_page.errors, status: :unprocessable_entity }
end
end
end
@ -272,6 +274,7 @@ class AdminController < ApplicationController
@first_page = FirstPage.where("page_type = 'project'").first
@course_page = FirstPage.where("page_type = 'course'").first
@first_page.web_title = params[:web_title]
@course_page.web_title = params[:web_title]
@course_page.title = params[:course_title]
@course_page.description = params[:course_description]
if @first_page.save && @course_page.save
@ -284,8 +287,10 @@ class AdminController < ApplicationController
end
else
respond_to do |format|
flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@course_page.errors.full_messages[0]}"
#flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}"
format.html {
course_page_made
render :action => 'course_page_made'
}
format.api { render_validation_errors(@first_page) }
@ -303,6 +308,7 @@ class AdminController < ApplicationController
@first_page = FirstPage.where("page_type = 'project'").first
@contest_page = FirstPage.where("page_type = 'contest'").first
@first_page.web_title = params[:web_title]
@contest_page.web_title = params[:web_title]
@contest_page.title = params[:contest_title]
@contest_page.description = params[:contest_description]
if @first_page.save && @contest_page.save
@ -315,8 +321,8 @@ class AdminController < ApplicationController
end
else
respond_to do |format|
flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@contest_page.errors.full_messages[0]}"
format.html {
contest_page_made
render :action => 'contest_page_made'
}
format.api { render_validation_errors(@first_page) }

View File

@ -1,3 +1,6 @@
class FirstPage < ActiveRecord::Base
attr_accessible :description, :title, :web_title,:page_type
validates_presence_of :web_title, :title, :description,:page_type
validates_length_of :web_title,:title, maximum: 30
validates_length_of :description, maximum: 100
end

View File

@ -266,6 +266,7 @@ zh:
field_value:
field_category: 类别
field_title: 标题
field_web_title: 浏览器标题
field_project: 项目
field_issue: 问题
field_status: 状态
@ -1909,6 +1910,7 @@ zh:
label_memo_create_fail: 发布失败
label_forum_create_succ: 贴吧新建成功
label_forum_create_fail: 贴吧新建失败
label_first_page_create_fail: 首页定制失败
label_forum_edit: 编辑讨论区
label_memo_create: 发布
label_memo_new: 新建主题

View File

@ -0,0 +1,8 @@
class SetWebTitle < ActiveRecord::Migration
def change
FirstPage.all.each do |fp|
fp.web_title = "Trustie - 为大学生技术创新筑巢"
fp.save
end
end
end

View File

@ -177,58 +177,6 @@ ActiveRecord::Schema.define(:version => 20140711012924) do
add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true
create_table "code_review_assignments", :force => true do |t|
t.integer "issue_id"
t.integer "change_id"
t.integer "attachment_id"
t.string "file_path"
t.string "rev"
t.string "rev_to"
t.string "action_type"
t.integer "changeset_id"
end
create_table "code_review_project_settings", :force => true do |t|
t.integer "project_id"
t.integer "tracker_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "updated_by"
t.boolean "hide_code_review_tab", :default => false
t.integer "auto_relation", :default => 1
t.integer "assignment_tracker_id"
t.text "auto_assign"
t.integer "lock_version", :default => 0, :null => false
t.boolean "tracker_in_review_dialog", :default => false
end
create_table "code_review_user_settings", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.integer "mail_notification", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "code_reviews", :force => true do |t|
t.integer "project_id"
t.integer "change_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "line"
t.integer "updated_by_id"
t.integer "lock_version", :default => 0, :null => false
t.integer "status_changed_from"
t.integer "status_changed_to"
t.integer "issue_id"
t.string "action_type"
t.string "file_path"
t.string "rev"
t.string "rev_to"
t.integer "attachment_id"
t.integer "file_count", :default => 0, :null => false
t.boolean "diff_all"
end
create_table "comments", :force => true do |t|
t.string "commented_type", :limit => 30, :default => "", :null => false
t.integer "commented_id", :default => 0, :null => false
@ -411,9 +359,9 @@ ActiveRecord::Schema.define(:version => 20140711012924) do
t.string "web_title"
t.string "title"
t.string "description"
t.string "page_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "page_type"
end
create_table "forums", :force => true do |t|
@ -807,7 +755,7 @@ ActiveRecord::Schema.define(:version => 20140711012924) do
t.integer "osp_id"
t.integer "parent_id"
t.string "subject", :null => false
t.text "content", :null => false
t.text "content", :limit => 16777215, :null => false
t.integer "author_id"
t.integer "replies_count", :default => 0
t.integer "last_reply_id"