ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

Not being able to use a cache key in rabl generated by controller. #81

Closed pamio closed 6 years ago

pamio commented 8 years ago

Hi, I've been using rabl-rails for sometime now and its great. But I'm not able to use a cache key generated by controller in the rabl template.

Here is the code

def some_action
   @cache_key = "#{params[:x]}-#{params[:y]}"
end

some_action.json.rabl

object :@brand, root: false
cache {|b| @cache_key}

Also I can't seem to be able to access the params hash in the rabl template. Is this intended ? How can I achieve this ?

Thanks in advance.

ccocchi commented 8 years ago

Hello,

Sadly the cache directive cannot is not evaluated in the context of the controller so you cannot access any variable from there nor the params hash. It was made only to have the object or collection available within the block.

pamio commented 8 years ago

Thanks for the clarification.