, .
2 :
- js fingerprint
- rails - ( rails)
, , ( capistrano) index.html. :
#my-other-app/index.html
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body >
<div id="awesome">
Some stuff here..
</div>
</body>
</html>
def self.generate_index_file
js_files = ['my_js_file.js']
tempfile = File.open Rails.root.join('my-other-app/index.tmp'), 'w'
f = File.new('my-other-app/index.html')
f.each do |line|
if line =~ /^.*<!-- BEGIN DYNAMIC URI -->/
tempfile << line
js_files.each do |filename|
fingerprinted_name = Rails.application.assets.find_asset(filename).digest_path
tempfile << "<script src='#{Rails.application.default_url_options[:host]}/assets/" + fingerprinted_name + "?body=1'></script>\n"
end
else
tempfile << line
end
end
f.close
tempfile.close
FileUtils.mv("my-other-app/index.tmp", "my-other-app/index.html")
end
namespace :deploy do
task :generate_samsung_index, roles: :app do
run %Q{cd #{latest_release} && RAILS_ENV=#{rails_env} bundle exec rails runner 'MyModel.generate_index_file'}
end
end
after "deploy:restart", "deploy:generate_samsung_index"
, ( ), URL-, <head>. :
def my_method
redirect_to "http://myawesomeurl.com?token=#{form_authenticity_token}"
end
#my-other-app/index.html
# On <head> with my previous code
<script language="javaScript" type="text/javascript">
meta1 = document.createElement("meta");
meta1.name = "csrf-param";
meta1.content = "authenticity_token";
$("head").append(meta1);
token = "token"
token_result = new RegExp(token + '=([^&]*)', 'i').exec(window.location.search)
meta2 = document.createElement("meta");
meta2.name = "csrf-param";
meta2.content = token_result;
$("head").append(meta1);
$("head").append(meta2);
</script>
, - .