Victor Ferreira
Victor Ferreira

Reputation: 6449

Rails not serving assets in development mode

Well it's the first time I set up a Rails app from the beginning and I just created my first view.

When I run the server I get a 404 Not Found error when trying to load the application.js file.

Layout

<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

environment/development.rb

...

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

...

And when I run on terminal rake assets:precompile I get this error:

rake aborted!

Don't know how to build task 'assets:precompile'

What is causing this?

Upvotes: 2

Views: 6119

Answers (3)

Anurag Kumar
Anurag Kumar

Reputation: 565

To resolve this, add the following to config/application.rb:

require 'sprockets/railtie'

For more information see here.

Upvotes: 3

Victor Ferreira
Victor Ferreira

Reputation: 6449

After running rake assets:precompile --tasks the precompile task was not listed.

I found out that a require on config/application.rb was missing:

require 'rails/all'

After adding this the app started precompiling and serving assets (actually there were minor errors with the gems I tried to install, I just had to remove the configuration files and then everything worked fine)

Upvotes: 0

Marko Manojlovic
Marko Manojlovic

Reputation: 91

Try to set config.assets.compile = true and try again. It should work after that.

Cheers!

Upvotes: 0

Related Questions