基于多线程的全局变量
程序员文章站
2022-03-06 23:47:34
...
def current_nation default_nation = (current_contact && current_contact&.company&.country) ? current_contact&.company&.country : "United States" cookie_country_id = cookies['country_id'].to_i contact_country_id = current_contact.try(:ship_nation).to_i country_id = cookie_country_id > 0 ? cookie_country_id : contact_country_id @current_nation = Nation.where(id: country_id).first if @current_nation.blank? cookies.delete('country_id') @current_nation = Nation.where(name: default_nation ).first end Product.current_nation = @current_nation&.name @current_nation end class Product < ApplicationRecord thread_mattr_accessor :current_nation, instance_accessor: true end
下一篇: 使用VBScript 中的类组织开发