Skip to content

Instantly share code, notes, and snippets.

@icegulch icegulch/action.rb forked from ahoward/action.rb
Last active Dec 20, 2015

Embed
What would you like to do?
# it's not critical for understanding
# but here is the associated server-side action
#
def version
@program = load_program!
@version = @program.versions.find(params[:version_id])
if stale?(:last_modified => @version.updated_at, :etag => @version.cache_key)
render
end
end
// today's quiz is simple:
//
// fork this code and explain, in english, what it does.
//
// suggest simpler alternatives.
//
// if the state (of the quiz) is NOT 'complete'
// pass the get variable to the head variable, both of which are functions that fetch data via ajax request
// seems to be determining latest version by comparing last modified times of server & browser
// most importantly, what if i don't like getting head?
if(state != 'complete'){
var get = function(){
jq.ajax({
'type' : 'GET',
'url' : url,
'cache' : false,
'success' : function(html){
version.replaceWith(html);
}
});
};
var head = function(callback){
jq.ajax({
'type' : 'HEAD',
'url' : url,
'success' : function(res, code, xhr){
var server_last_modified = xhr.getResponseHeader("Last-Modified");
if(Date.parse(server_last_modified) > Date.parse(last_modified)){
callback();
};
}
});
};
head(get);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.