I'm trying to replicate the following Rails method, but using JQuery:
Rails.cache.exist?("ped_basic")
Does anyone know how to do this?
I am still experimenting with the optimal way to do this, but I've ended up using the 'Gon' gem to create a variable in my controller method (before_filter) that is able to be referenced by Rails as well as by jQuery.
In my controller method, I set my cache key equal to a gon.variable value, then can access the variable in jQuery via the same gon.variable name.
In other words:
#Controller method
before_filter :set_gon_vars
def set_gon_vars
gon.variable1 = Rails.cache.exist?("cache1")
gon.variable2 = Rails.cache.exist?("cache2")
gon.variable3 = Rails.cache.exist?("cache3")
end
The the variables can be accessed in my coffeescript code by simply referencing the same gon.variable name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With