Skip to content

Instantly share code, notes, and snippets.

View xiaohui-zhangxh's full-sized avatar

xiaohui xiaohui-zhangxh

  • Tanmer Inc.
  • 中国
View GitHub Profile
@xiaohui-zhangxh
xiaohui-zhangxh / create_engine
Last active March 6, 2023 06:00
Rails 项目在 engines/ 目录下生成子模块 engine
#!/usr/bin/env ruby
name = ARGV[0]
if name.to_s.strip.empty?
puts "usage: bin/create_engine <name>"
exit(1)
end
cmd = <<-CMD
bin/rails plugin new engines/#{name}_engine \
@xiaohui-zhangxh
xiaohui-zhangxh / liquid_template_tags_thread_safe.rb
Last active March 9, 2023 02:22
Make liquid template's tags to be thread safe
# 使用方法:
#
# Liquid::Template.include Liquid::TemplateTagsThreadSafe
#
# Liquid::Template.with_thread_safe do
# Liquid::Template.register_tag('test', Liquid::Tag)
# Liquid::Template.tags['test'] # => Liquid::Tag
# end
#
# Liquid::Template.tags['test'] # => nil
@xiaohui-zhangxh
xiaohui-zhangxh / application_controller.rb
Last active January 6, 2024 11:20
Make active_model_serializers render Pagy result as jsonapi response, with pagination meta and links
class Api::ApplicationController < ActionController::API
include Pagy::Backend
include PagyCollectionSerializer::ControllerMixin
end
@xiaohui-zhangxh
xiaohui-zhangxh / dynamic_cookie_store.rb
Created December 31, 2023 10:49
Make dymanic session store key for Rails on Multi-Tenant Arch