From 76cd916a26a27fb57939c2219c52eda776c363f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Thu, 14 Mar 2024 20:10:33 +0800 Subject: [PATCH] Fix PropertyHireSetting. --- app/controllers/property_hires_controller.rb | 4 ++-- app/models/property.rb | 6 +++--- lib/property_hire/engine.rb | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index abac7f1..6af06c5 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -240,7 +240,7 @@ class PropertyHiresController < ApplicationController index_page = is_admin_page ? "/#{I18n.locale}/admin/property_hires" : "/#{I18n.locale}#{params[:url]}" end hire_page = is_admin_page ? request.referer : "#{index_page}?method=hire" - need_validate = (PropertyHireSetting.last.allow_no_logins_user rescue false) && current_user.nil? + need_validate = (PropertyHireSetting.first.allow_no_logins_user rescue false) && current_user.nil? session.delete(:hire_data) if need_validate unless gotcha_valid? @@ -324,7 +324,7 @@ class PropertyHiresController < ApplicationController else hire = PHire.new(:id=>nil) end - allow_no_logins_user = PropertyHireSetting.last.allow_no_logins_user + allow_no_logins_user = PropertyHireSetting.first.allow_no_logins_user all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.id.to_s,s.title]}]}.to_h { "hire" => hire, diff --git a/app/models/property.rb b/app/models/property.rb index 734ed16..14e97f6 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -151,10 +151,10 @@ class Property end end def calendar_type - (self.custom_calendar_type == 0 ? (PropertyHireSetting.last.calendar_type rescue 0) : (self.custom_calendar_type - 1)) + (self.custom_calendar_type == 0 ? (PropertyHireSetting.first.calendar_type rescue 0) : (self.custom_calendar_type - 1)) end def self.init_class_variables - setting = PropertyHireSetting.last + setting = PropertyHireSetting.first if setting @@disable_content_page = setting.disable_content_page rescue false @@disable_view_calendar_page = setting.disable_view_calendar_page rescue false @@ -530,7 +530,7 @@ class Property times end def carousel_image_width - (self.custom_carousel_image_width.blank? ? PropertyHireSetting.last.carousel_image_width : self.custom_carousel_image_width) rescue "75%" + (self.custom_carousel_image_width.blank? ? PropertyHireSetting.first.carousel_image_width : self.custom_carousel_image_width) rescue "75%" end def get_attribute_value(attribute_field, signup_id) SeminarSignupValue.find_by(seminar_signup_field_id: attribute_field.id, seminar_signup_id: signup_id) diff --git a/lib/property_hire/engine.rb b/lib/property_hire/engine.rb index 4860b9b..012f744 100644 --- a/lib/property_hire/engine.rb +++ b/lib/property_hire/engine.rb @@ -13,8 +13,11 @@ module PropertyHire data_count 1..30 require File.expand_path('../../../app/models/property_hire_setting', __FILE__) if defined?(PropertyHireSetting) - if PropertyHireSetting.count == 0 + settings_count = PropertyHireSetting.count + if settings_count == 0 PropertyHireSetting.create + elsif settings_count > 1 + PropertyHireSetting.all[1..-1].each{|s| s.destroy} end end