Instantly share code, notes, and snippets.
Last active
September 23, 2019 14:50
Show Gist options
-
Select an option
No results found
Learn more about clone URLs
Clone this repository at <script src="https://gist.github.com/devil6x/000e4644e3b1c21e3a16171521714264.js"></script>
-
Save devil6x/000e4644e3b1c21e3a16171521714264 to your computer and use it in GitHub Desktop.
Select an option
No results found
Learn more about clone URLs
Clone this repository at <script src="https://gist.github.com/devil6x/000e4644e3b1c21e3a16171521714264.js"></script>
Save devil6x/000e4644e3b1c21e3a16171521714264 to your computer and use it in GitHub Desktop.
Download ZIP
Subscription popup backend example
Raw
callback.html.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<script> |
|
var data = JSON.parse(decodeURIComponent('<%= URI::escape( @data.to_json ) %>')); |
|
window.addEventListener("message", function(ev) { |
|
if( (ev.data === 'getSubscriptionData')) { |
|
ev.source.postMessage(data, '*'); |
|
window.close(); |
|
} |
|
}); |
|
setTimeout(function() { |
|
document.getElementById('text').innerHTML = (data && data.error) || 'Redirecting...'; |
|
}, 1000); |
|
</script> |
|
</head> |
|
<body> |
|
<pre id="text"> |
|
</pre> |
|
</body> |
|
</html> |
Raw
controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
|
# frozen_string_literal: true |
|
|
|
class SubscriptionsController < ApplicationController |
|
|
|
|
|
def index |
|
data = params |
|
render_data('getSubscriptionData', data) |
|
end |
|
|
|
private |
|
|
|
def render_data(message, data) |
|
@data = data.merge(message: message) |
|
render layout: nil, template: 'callback' |
|
end |
|
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment