I have an Active Resource model that needs to set a header before posting/putting through save and update_attributes. The issue is that the header value needs to be different for each user, so it can't be set at the model level. I've seen examples for setting headers as part of a find
, get
, or custom methods, but no way to add it to a @myclass.save
. Something like prefix_options
but for headers would be ideal (@myclass.prefix_options[:myvar] = 'abcd'
) but I haven't found anything like that. Any insight would be appreciated.
I just had a similar problem and overrode .headers
on my ActiveResource class. ActiveResource::Base.headers
is just a hash by default, but you can override it to be a method! <3 U Ruby.
http://rmosolgo.github.io/blog/2014/02/05/dynamically-generated-headers-for-activeresource-requests/