我正试图从Sprockets切换到Webpacker,并且主要使用此指南:
https://medium.com/@coorasse/goodbye-sprockets-welcome-webpacker-3-0-ff877fb8fa79
还有其他一些指南,但是初始步骤是相同的。
我密切关注了所有内容,没有发现任何错误,但是“ Hello World from Webpacker”未在控制台中显示,表明它未正确链接js文件。我先安装了yarn,没有问题地安装了webpacker,然后将其添加到app / views / layouts / application.html.erb:
<%= javascript_pack_tag 'application' %>
几次重新启动服务器,没有运气。有什么想法吗?
编辑1:正如一位评论者所要求的,以下是我检查源代码时正在运行的所有脚本:
<script src="/assets/rails-ujs.self-2b8935521e2301b06b45bd42e623eb0c0acf76c3a6ba383b7429c6a2884f8c23.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/activestorage.self-1ed4604ac2170045f1ffca4edb81a75246661555e4f9cf682bb8a21825e32e1c.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/turbolinks.self-569ee74eaa15c1e2019317ff770b8769b1ec033a0f572a485f64c82ddc8f989e.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/jquery3.self-e200ee796ef24add7054280d843a80de75392557bb4248241e870fac0914c0c1.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/popper.self-70e1b2b78096eb80eb35ebac513e7a8007033ee3e881919cfdca4ece7779cffd.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/bootstrap.self-91405a85c7ea7ffc2407472f08a86cd29ba078b4e18f962931a4cf3270a7ba4d.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/lib/abstract-chosen.self-ff43f2db4e91fea824844eb4d37566bc7248e435c3ea7050d7a252c1c14e4d9a.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/lib/select-parser.self-16f32cef24f1cae19e8b5f5dab3ac72e6fb35ce24fe5ae41d354d60f9bb53491.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/chosen.jquery.self-c1b0ad79c75d520f72310f2594a76189b7c6e407c035a9a4c9022dff262b49a5.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/chosen-jquery.self-6a3cf5192354f71615ac51034b3e97c20eda99643fcaf5bbe6d41ad59bd12167.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/action_cable.self-69fddfcddf4fdef9828648f9330d6ce108b93b82b0b8d3affffc59a114853451.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/cable.self-8484513823f404ed0c0f039f75243bfdede7af7919dda65f2e66391252443ce9.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/google_places.self-dff88f7305718f246a9ed130e8ec03a82098539df2a08ff9774a610bc84d42ca.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/merge_requests.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/application.self-6a7f81c89608537f1c0b5e6e1a1cad14caec515ae09b88e0406efa9bcbfd4752.js?body=1" data-turbolinks-track="reload"></script>
在app / views / layouts / application.html.erb中,我具有以下标记:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
我知道后两个javascript标签可能会以某种方式发生冲突,但是如果我将旧标签完全取出,不会有什么区别。
已解决:当然,这确实是一个愚蠢的错误。我网站的主页是唯一不使用应用程序布局的页面。它有自己的。没有问题,只要我尝试其他页面就可以了。 gh。
答案 0 :(得分:0)
我最终做了同样的事情。将<%= javascript_pack_tag 'application' %>
保留在app / views / layouts / application.html.erb
运行rails g controller pages index
转到localhost:3000/pages
这就是我找到控制台的地方
在配置/路由中确认您具有:
resources :pages