Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save viniciusnz/c3093ff73458be18caf575f36b4f120d to your computer and use it in GitHub Desktop.
Save viniciusnz/c3093ff73458be18caf575f36b4f120d to your computer and use it in GitHub Desktop.
# for all options ended in _id, setup the instance variable for liquid
options.select{|k,v| k.to_s.ends_with?('_id')}.each do |k,v|
new_key = k.to_s.gsub(/_id\z/, '')
instance = Resource.resource_by_table_name(new_key.pluralize)&.model&.find_by(id: v)
if instance.present?
# puts ["@" + new_key, v]
instance_variable_set("@" + new_key, instance)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment