ajax - Rails Controller Check if Turbolinks Request -


i developing ruby on rails 4 application using turbolinks gem. have noticed when link clicked layout still rendered server side turbolinks javascript grabs body out of rendered content. question on controller side possible determine if request made via turbolinks or not. in event request made via turbolinks want set layout false not execute un-needed code. in applicationcontroller have following code:

# don't use layout when ajax request layout proc { |controller| controller.request.xhr? ? false: "application" } 

this code prevents ajax request rendering header if make ajax request via jquery, doesn't seem when comes turbolinks.

although bit of hack, found checking header "x-xhr-referer" seems trick.

unless request.headers["x-xhr-referer"].present?      do_some_stuff end 

it seems turbolinks add header redirection handling. may change in future though.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -