Last active
June 8, 2020 21:27
-
-
Save alexishida/a0b682eceb31a684c9ead34b4d682bc5 to your computer and use it in GitHub Desktop.
Config de Assets Javascript Vendor Turbolinks no Rails
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
# Colocar no layout | |
<%= csrf_meta_tags %> | |
<%= csp_meta_tag %> | |
<%= stylesheet_link_tag 'application', media: 'all' %> | |
<%= stylesheet_link_tag params[:controller] if !stylesheet_exists?(params[:controller]) %> | |
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> | |
<%= yield :javascript %> | |
<%= javascript_include_tag params[:controller] if javascript_exists?(params[:controller]) , 'data-turbolinks-track': 'reload' %> | |
# Colocar na pagina específica | |
<% content_for :javascript do %> | |
<%= javascript_include_tag 'scriptjs', 'data-turbolinks-track': 'reload' %> | |
<% end %> | |
# Configurando plugins de terceiros no vendor config/initializers/assets.rb | |
Rails.application.config.assets.paths << Rails.root.join("vendor", "assets") | |
Rails.application.config.assets.precompile += %w( *.js *.css ) | |
Rails.application.config.assets.precompile += %w(*.svg *.eot *.woff *.ttf) | |
# Listar todos os assets que estao ativos | |
Rails.application.assets.each_file { |pathname| puts pathname} | |
# Colocar antes dos codigos jquery | |
document.addEventListener("turbolinks:load", function () { | |
$(document).ready(function(){ | |
... | |
}); | |
}); | |
# Desabilitando turbolinks | |
<div data-turbolinks="false"> | |
</div> | |
<head> | |
// ... | |
<%= yield :stylesheets %> | |
</head> | |
<%= provide :stylesheets do %> | |
// your page-specific css | |
<% end %> | |
<body class="<%= controller_name %>-<%= action_name %>"> | |
<%= yield %> | |
</body> | |
.controller_name-action_name { | |
// your css goes here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment