新增:项目语言新增唯一性验证

This commit is contained in:
yystopf 2022-10-17 10:52:57 +08:00
parent 8d41c27044
commit 8807be6e4d
2 changed files with 6 additions and 3 deletions

View File

@ -27,17 +27,18 @@ class Admins::ProjectLanguagesController < Admins::BaseController
flash[:success] = '创建成功' flash[:success] = '创建成功'
else else
redirect_to admins_project_languages_path redirect_to admins_project_languages_path
flash[:danger] = '创建失败' flash[:danger] = @project_language.errors.full_messages.join(",")
end end
end end
def update def update
if @project_language.update_attribute(:name, @name) @project_language.attributes = {name: @name}
if @project_language.save
redirect_to admins_project_languages_path redirect_to admins_project_languages_path
flash[:success] = '更新成功' flash[:success] = '更新成功'
else else
redirect_to admins_project_languages_path redirect_to admins_project_languages_path
flash[:success] = '更新失败' flash[:danger] = @project_language.errors.full_messages.join(",")
end end
end end

View File

@ -12,4 +12,6 @@
class ProjectLanguage < ApplicationRecord class ProjectLanguage < ApplicationRecord
include Projectable include Projectable
validates :name, uniqueness: true
end end