rubysherpas / forem

The best Rails 3 and Rails 4 forum engine. Ever.
http://forem.herokuapp.com
MIT License
1.55k stars 423 forks source link

Asset Precompile error #320

Closed indieambassador closed 11 years ago

indieambassador commented 12 years ago

When I push to heroku, I am getting a strange issue. I am using twitter-bootstrap-rails and forem with devise in my app.

Regardless of what I do, I get this when I push to Heroku:

Preparing app for Rails asset pipeline
  Running: rake assets:precompile
  rake aborted!
  undefined method `path' for nil:NilClass
  (in /tmp/build_zd811t1inisx/vendor/bundle/ruby/1.9.1/bundler/gems/forem-66686a7e618c/app/assets/javascripts/forem.js.erb)

If i have twitter-bootstrap-rails in the :assets group, then the app will crash with this error:

ActionView::Template::Error (couldn't find file 'twitter/bootstrap'
2012-10-18T15:27:07+00:00 app[web.1]:   (in /app/app/assets/javascripts/application.js:15)):

This was working before i installed forem. I have a feeling the rake task failing due to the forem.js.erb fil error is causing this.

If i remove the twitter-bootstrap-rails gem from the assets group, i still get the assets precompile error, but the app loads in heroku just fine. not sure what's going on here.

also, somehow during the troubleshooting of this issue, the application.css.scss file stopped being parsed. the included files are parsed, but not the code in the file it self. strange.

I haven't been able to find anyone else in the 'issues' section with this issue. If any one could lend some insight to this problem, i would really appreciate it. Thanks!

I am a bit new to rails, so sorry for the n00b issue. I am looking for tips on how to troubleshoot this.

focused commented 12 years ago

I have the same issue.

Heroku requires this setting in config/application.rb:

config.assets.initialize_on_precompile = false

With this setting this file will not be compiled. To solve this problem you can try different compilation options like runtime compiling (I did not try), other is to patch this file. Any help is highly appreciated.

parndt commented 12 years ago

Ideally Forem would not get in the way of compiling on Heroku when using:

config.assets.initialize_on_precompile = true

There is a lot of misinformation around about "Heroku requiring this setting" which is not strictly true.. Heroku only requires this when you're using an application that incorrectly accesses the database before the application is initialized. It's good to avoid this on any Rails application.

Do assets fail to precompile on a default Rails application with Forem included or is this coming from something else in your Gemfile?

Thanks!

focused commented 12 years ago

Yes, default Rails application with Forem fails to precompile the asset app/assets/javascripts/forem.js.erb with this setting set to false. Any suggestions?

parndt commented 12 years ago

Does it work when set to true? (The default)

focused commented 12 years ago

Yes, it is.

oeoeaio commented 12 years ago

I resolved this issue by using the experimental user-env-compile feature of Heroku Labs.

See here for usage instructions: https://devcenter.heroku.com/articles/labs-user-env-compile

It is also possible to run bundle exec rake assets:precompile locally, commit public/assets/ and push to Heroku, but I find this annoying.

Neither of these options require config.assets.initialize_on_precompile = false

willcosgrove commented 11 years ago

I had a similar problem but none of the above solutions worked for me. It ended up being because I set a different engine name with the mount 'as' option. Which was making this line: https://github.com/radar/forem/blob/master/app/assets/javascripts/forem.js.erb#L4 fetch something that didn't exist.

Just something to be aware of. If you run into this problem, remove the 'as' option on the mount call in the routes file.

radar commented 11 years ago

I thought we had a warning on the mount line that said something like "pretty please don't use :as", or maybe I am confusing that with spree.

parndt commented 11 years ago

We should have it, if we don't!

willcosgrove commented 11 years ago

You might, but I'm the same guy that the forem:install failed for, so I didn't get any messages :(

eostrom commented 11 years ago

I'm seeing this error and I'm not using :as. Is the resolution here that Forem is incompatible with initialize_on_precompile = false?

parndt commented 11 years ago

Yep please initialise the environment on precompile.

eostrom commented 11 years ago

OK. I added a wiki page recommending user-env-compile or local asset compilation. [Update: This project's wiki, not Wikipedia!]

llexa313 commented 11 years ago

I don't use :as, but user-env-compile and initialize_on_precompile = true didn't help for me:

Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

I wrote little monkey patch in application.rb and it work for me.

config.assets.initialize_on_precompile = false
...
routes.named_routes[:forem] ||= Journey::Route.new(nil, nil, Journey::Path::Pattern.new("\forums"), {})

Maybe it will help someone else

radar commented 11 years ago

@llexa313: That problem looks like something to do with your database setup. initialize_on_precompile should be false if you're using Heroku.

parndt commented 11 years ago

@radar It doesn't have to be false; some applications actually require you set this to true (I thought we did?). That's why Heroku have:

heroku labs:enable user-env-compile
pwalker commented 11 years ago

I can't get my assets to precompile anywhere, local or heroku, with or without user-env-compile, and with initialize_on_precompile set to both true and false. I'm still erroring out at the mentioned line, any ideas or how to debug this? There are a lot of partial solutions here, and wiki page was rather short on the subject.

focused commented 11 years ago

You can just override and hardcode this, thats how we solve this for Heroku then.

austencollins commented 11 years ago

Just getting started with Forem and I am running into this same issue. I've tried all of the solutions above, but this gem will not allow me to deploy to Heroku. How else has everyone been working around this?

radar commented 11 years ago

@ac360: Is it possible for you to give me (radarlistener@gmail.com) access to your Heroku application so that I can attempt to deploy it and see these errors for myself? That would really help me to be able to debug it. If you're not able/willing to do that, then attempt to reproduce this issue in a brand new app with the same Gemfile. If you're able to reproduce it there, then please share with us that Gemfile and I'll attempt to reproduce it myself.

Thanks!

ghost commented 11 years ago

I'd just like to +1 this issue and add a bit of my own experience, (not sure if this will help or just muddle the issue, but...):

I'm using Forem on two different apps, both are running Rails 3.2.13. I was having the same issue described by everyone else, but was able to solve it in one of the apps by including the initialize_on_precompile = true directive in application.rb. I duplicated the fix on my other app -- and no joy. It seems bizarre that two apps running on the same version of rails would react differently, but that's my situation. If it helps:

bundle list for the 'working' app:

bundle list for the 'broken' app:

Again -- not sure this helps resolve the problem -- one other thing to note is that I am not using heroku