From dd83b8ef706e38b0b73175a19c37ef83b8432646 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Wed, 20 May 2026 13:20:28 +0800 Subject: [PATCH] Fix update and delete,Add acquired_date --- .../admin/certificates_controller.rb | 34 +++++++++++++------ app/models/certificate.rb | 3 +- app/views/admin/certificates/_form.html.erb | 10 +++++- app/views/admin/certificates/destroy.js.erb | 1 + config/locales/en.yml | 3 +- config/locales/zh_tw.yml | 3 +- 6 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 app/views/admin/certificates/destroy.js.erb diff --git a/app/controllers/admin/certificates_controller.rb b/app/controllers/admin/certificates_controller.rb index 461bb0d..29caf4c 100644 --- a/app/controllers/admin/certificates_controller.rb +++ b/app/controllers/admin/certificates_controller.rb @@ -31,17 +31,29 @@ class Admin::CertificatesController < OrbitMemberController @intro = @intro.nil? ? CertificateIntro.new({:member_profile_id=>@member.id}) : @intro end - def destroy - @course.destroy - redirect_to admin_courses_path(:page => params[:page]) - end - - def update - @course.update_attributes(course_params) - @course.save - redirect_to params[:referer_url] - end +def destroy + @certificate.destroy + respond_to do |format| + # 刪除後,直接導向證照的總列表網址 + format.html { redirect_to(admin_certificates_url) } + format.js + format.json { render json: { "success" => true } } + end + end + def update + @member = @certificate.member_profile rescue nil + # 使用正確的證照參數:certificate_params + @certificate.update_attributes(certificate_params) + @certificate.save + + if params[:desktop] == "true" + render json: { "data" => get_paper_list }.to_json + else + # 更新成功後,直接跟隨表單帶過來的來源網址返回 + redirect_to params['referer_url'] + end + end def update_frontend_setting @member = MemberProfile.find(params['member_profile_id']) rescue nil @intro = CertificateIntro.find_by(:member_profile_id=>@member.id) rescue nil @@ -89,4 +101,4 @@ class Admin::CertificatesController < OrbitMemberController end @certificate = Certificate.find_by(:uid => uid) rescue Certificate.find(params[:id]) end -end \ No newline at end of file +end diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 0f04684..aac4e4e 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -6,6 +6,7 @@ class Certificate include Slug field :issued_by + field :acquired_date, type: Date field :title, as: :slug_title, type: String, localize: true belongs_to :member_profile @@ -85,4 +86,4 @@ class Certificate } end -end \ No newline at end of file +end diff --git a/app/views/admin/certificates/_form.html.erb b/app/views/admin/certificates/_form.html.erb index 951479e..d7d0d1f 100644 --- a/app/views/admin/certificates/_form.html.erb +++ b/app/views/admin/certificates/_form.html.erb @@ -101,6 +101,14 @@ + +
+ +
+ <%= f.datetime_picker :acquired_date, :no_label => true, :format=>"yyyy/MM/dd", :placeholder=>"YYYY/MM/DD", :value => @certificate.acquired_date, :new_record => @certificate.new_record? %> +
+
+ @@ -122,4 +130,4 @@ <%= f.submit t('submit'), class: 'btn btn-primary' %> <%= link_to t('cancel'), request.referer, :class=>"btn" %> - \ No newline at end of file + diff --git a/app/views/admin/certificates/destroy.js.erb b/app/views/admin/certificates/destroy.js.erb new file mode 100644 index 0000000..d8ab5f6 --- /dev/null +++ b/app/views/admin/certificates/destroy.js.erb @@ -0,0 +1 @@ +$('#certificate_<%= @certificate.id.to_s %>').remove(); diff --git a/config/locales/en.yml b/config/locales/en.yml index b6e6448..639c538 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,5 +5,6 @@ en: certificate: Certificate personal_certificate: issued_by: Issued By + acquired_date: Acquired date certificate: Certificate - title: Certificate \ No newline at end of file + title: Certificate diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index fd507f1..83ec92b 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -5,5 +5,6 @@ zh_tw: certificate: 證照 personal_certificate: issued_by: 發照單位 + acquired_date: 取得日期 certificate: 證照名稱 - title: 證照名稱 \ No newline at end of file + title: 證照名稱