欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

基于多线程的全局变量

程序员文章站 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
相关标签: 多线程 thread