Rails无法在开发模式下提供资产

问题描述 投票:1回答:3

好吧,这是我从头开始第一次设置Rails应用程序,而我只是创建了第一个视图。

当我运行服务器时,尝试加载application.js文件时出现404 Not Found错误。

布局

<html>
  <head>
    <%= yield :head %>
  </head>
  <body>
    <h1>If you're not and Admin you shouldn't be here!</h1>
    <%= yield %>

    <%= javascript_include_tag 'application' %>
    <% yield :script %>
    <script>

      $(function(){
        alert('Hey')
      })
    </script>
  </body>
</html>

的application.js

//= require jquery

环境/ development.rb

...

config.assets.debug = false
config.assets.compile = false
config.assets.digest = true

...

当我在终端rake assets:precompile上运行时,出现以下错误:

耙子流产了!

不知道如何建立任务'assets:precompile'

是什么原因造成的?

ruby-on-rails ruby ruby-on-rails-4 asset-pipeline
3个回答
2
投票

要解决此问题,请将以下内容添加到config/application.rb

require 'sprockets/railtie'

有关更多信息,请参见此处。


0
投票

尝试设置config.assets.compile = true然后重试。 在那之后它应该工作。

干杯!


0
投票

运行rake assets:precompile --tasks ,未列出预编译任务。

我发现缺少对config/application.rb的要求:

require 'rails/all'

添加此应用程序后,该应用程序开始预编译并提供资产(实际上,我尝试安装的gem存在一些小错误,我只需要删除配置文件,然后一切正常即可)

© www.soinside.com 2019 - 2024. All rights reserved.