Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot rake assets:precompile without database #78

Closed
axlekb opened this issue Sep 9, 2013 · 17 comments
Closed

Cannot rake assets:precompile without database #78

axlekb opened this issue Sep 9, 2013 · 17 comments

Comments

@axlekb
Copy link

axlekb commented Sep 9, 2013

I'm trying to deploy my Rails app to Heroku, and that involves precompiling assets. Heroku's help pages say that the best way to figure out what is causing the problem is to change your database.yml file to point to a non-existant database.

So I've run rake assets:precompile without a database and it fails due to the acts_as_tree inclusion in one of my models. When I comment out acts_as_tree, the assets compile successfully.

I did a quick look around, but couldn't find anything obvious. I'm obviously a little bit out of my comfort zone here, but I'd love to not have Heroku compile my assets when pushing rather than having to have my compiled assets as part of the repository.

Any help/insight/guidance appreciated.

@mceachen
Copy link
Collaborator

Can you include the error?

Thanks.

@axlekb
Copy link
Author

axlekb commented Sep 10, 2013

Here's a gist

@axlekb
Copy link
Author

axlekb commented Sep 12, 2013

@mceachen, any ideas on this? I think it's support.rb#L24. I guess I'll try to branch to see if this is it.

@axlekb
Copy link
Author

axlekb commented Sep 18, 2013

Haven't been able to look at this much recently, but I have been able to narrow it down to a specific line within the acts_as_tree method here: acts_as_tree.rb#L24. So if I comment this line out, I can precompile assets successfully without requiring a database.

I'll let you know as I figure anything out. Please let me know if this is making any sense to anyone else, or why closure_tree is even required when compiling assets.

@axlekb
Copy link
Author

axlekb commented Sep 18, 2013

Also found this pull request for awesome_nested_set that seems related from a few years ago.

@axlekb
Copy link
Author

axlekb commented Sep 18, 2013

And here's another pull request. I wish I had the time to help, but I just decided to use awesome_nested_set in the short term.

@mceachen
Copy link
Collaborator

mceachen commented Oct 5, 2013

Sorry for the delay, I'll try to get to this over the weekend.

@mceachen
Copy link
Collaborator

mceachen commented Oct 6, 2013

@axlekb , can you check this out? http://stackoverflow.com/a/18545752/172310

If not, I could add a rescue (but for what? a database connection error?) in ClosureTree::ActsAsTree#acts_as_tree so the includes would go ignored.

@axlekb
Copy link
Author

axlekb commented Oct 6, 2013

I did not try that out. I wish I knew more about compiling assets and the such, but it was much easier for me to switch to awesome_nest_set instead. Not sure why that gem does not have the same issue.

@mceachen
Copy link
Collaborator

mceachen commented Oct 6, 2013

OK!

Note that I wrote closure tree due to performance issues with nested set
implementations. If you don't have that many nodesn in your tree, you'll be
fine, but just know it doesn't scale well.

Thanks for taking the time to try to debug this!

@axlekb
Copy link
Author

axlekb commented Oct 6, 2013

Yeah, I was excited about closure tree because of its dedication to performance. Unfortunately, having to manage commited compiled assets is worse to me than a bit of slow performance with hierarchies.

@mceachen
Copy link
Collaborator

mceachen commented Oct 6, 2013

OK, branch heroku_asset_compilation should work (it does for me, at least):

Add this to your Gemfile:

gem 'closure_tree', github: 'mceachen/closure_tree', branch: 'heroku_asset_compilation'

and then bundle update

If you're good, I'll push it out as v4.2.9.

@mceachen
Copy link
Collaborator

I pushed v4.2.9. YOU WILL LOVE IT

@axlekb
Copy link
Author

axlekb commented Oct 10, 2013

Sorry, just getting back to this now. I tried switching back to closure_tree and am running into postgres errors. Don't have time to figure out what's causing this immediately, but if this error means anything to you, let me know.

ActiveRecord::StatementInvalid:
       PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
       : SELECT pg_advisory_unlock(2085799232), 1381413498.851916

@mceachen
Copy link
Collaborator

No. I'd need more context to know what's wrong.

That advisory lock is what I had to do to ensure consistency within the
hierarchies table, though, so it's still something that might involve this
gem.

Did you call #rebuild! on your model when you switched back?

Thanks for taking another swing.

@axlekb
Copy link
Author

axlekb commented Oct 10, 2013

Sorry, I initially failed to follow directions. But... I'm still having some issues on precompiling assets. The test that heroku suggested was to change database.yml to reference a database that doesn't exist. If I can rake assets:precompile with that change, then heroku will be able to compile the assets. Unfortunately that test fails, but if I remove acts_as_tree from my model, it succeeds. I tried putting acts_as_tree at the end of my model too.

I should also note that the model that throws the error is a subclass of a single table inheritance model that contains acts_as_tree. Not sure if that might be a source cause a problem since it looks like order is important.

@axlekb
Copy link
Author

axlekb commented Oct 11, 2013

You randomly made my twitter feed today. Sorry about the fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants