Uninitialized constant ApplicationController::Ability on Heroku - heroku

I have a rails 4 application successfully running locally with cancan. But when I push it to Heroku, I get this error, each time the code tries to authorize anything
Uninitialized constant ApplicationController::Ability
Looking at the logs, it looks like its failing in this method, which I have in my application controller. Any idea what is going on?
def current_ability
#current_ability ||= Ability.new(current_user, load_service_provider_from_host)
end
This works fine on my local machine.

I managed to figure out what the issue is. The issue was, my ability class file was named Ability.rb. Note the upper case. When I changed it to lower case (ability.rb), just like all the other models, it worked fine. It still would be nice to know why this failed only on heroku and not locally.

Related

Laravel 5.3 not logging

I’ve inherited a Laravel 5.3 application that does not appear to be logging web processes or anything else on the server-side in my development environment. Here’s the things I’ve tried/confirmed.
Set APP_DEBUG = true
storage/logs exists and all users have read/write/execute permissions
I’ve created an empty laravel.log file, thinking it needs to exist before it can be written to. I’ve also run the app without that file.
FWIW, this app is running in a vagrant instance and has debugger bar installed.
Any thoughts on what is going on here or something I can try to get logging started?
Thanks.
I found it hiding in the vagrant instance here: /var/log/nginx
That solved, I'd still be grateful for any insight or resource as to how or why that's configured. Knowing this and searching within the project and combing through the Vagrantfile still doesn't shed light on why it's being saved there rather than storage/logs.

ActiveJob instance freezes RSpec test

I have an after_create_commit callback on my model, Foo, which looks like this:
after_create_commit { LogBroadcastJob.perform_later self }
I've reduced my perform method to return nil to simplify things.
When I create a Foo instance in an RSpec test with factory_girl, the test suite freezes. This only happens when I test models with that callback.
FactoryGirl.create :foo
When I Ctl+C out of my test suite it fails to kill the process. I have to find the process, which is still using my database (Postgresql), and kill it, which means that I don't see any errors on the command line. If I run my test suite again, it creates another process that I have to find and kill.
Does this sound familiar to anyone? How would I find useful errors here?
Maybe relevant: I upgraded from Rails 4.2 to 5.0.0.1 a while back.
This was a concurrency issue. Thanks to the resource provided in #coreyward's comment, I was able to clear this up by setting config/environments/test.rb to
config.eager_load = true
This differs from my config in config/environments/development.rb (and everything works in development), so I can't say I understand yet why it works. But I can now run all my tests with bundle exec guard or bundle exec rake spec.

sinatra app stalls in production mode when deployed via vagrant to a VM and provisioned by varnish and run as a deamon

I have a sinatra app, when I run it in production it acts odly.
The first requests works, assets download and the page loads.
If you refresh the page however the request just stalls, and nothing gets logged out to the log file.
I'm running with sinatra-asset-pack and I did precompile the assets before starting it.
I'd post code but I'm not sure what would be needed to work out the issue
EDIT: it works fine on my own box, but when I deploy it to a VM using vagrant it just ceases up in production mode, it's fine in development mode though.
EDIT: I was able to get it to spit out this error:
Errno::EPIPE
Broken pipe # io_write -
And narrow it down to an action, however posting the code in the action is pointless as it doesn't log anything out and the first line of the action is a logging action so I'm not sure the action gets run at all; the logging was added after the problem hit so whatever it is, I don't think it's that.
EDIT: the error actually occurs here (base.rb(1144) of sinatra:
1142 def dump_errors!(boom)
1143 msg = ["#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{boom.class} - #{boom.message}:", *boom.backtrace].join("\n\t")
1144 #env['rack.errors'].puts(msg)
1145 end
EDIT: Ok, so when I run the deployment command manually it works fine; weirdly the output from the server is still being outputted to the terminal despite it being forked, I wonder if that's the problem. The broken pipe is the terminal that no-longer exists (when deployed via chef) and as such it's breaking... maybe?
Ok, turns out that the broken pipe thing was the cause, for some reason even after being forked it was trying to write stdout and stderr to the terminal.
However because the terminal no longer existed (It's started by chef) it could no longer write to the output and thus locked up, starting the app manually on the VM allowed it to work and further evidence to this conclusion is that adding a redirect (>> app.log 2>&1) to the end of the start command allowed the app to work.
Why sinatra is still writing logs to the terminal instead of the file I don't know and I need to work that out, but the main issue of the why is solved.
EDIT:
In the end I'm just doing this:
$stderr = #log.file
$stdout = #log.file
to redirect it to the same place as my logs go so it should be fine now... I think?

Using redis with heroku

This is my first time using redis and the only reason I am is because I'm trying out autocomplete search tutorial. The tutorial works perfectly in development but I'm having trouble setting up redis for heroku.
I already followed these steps on the heroku docs for setting up redis but when I run heroku run rake db:seed I get Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
I'm not very familiar with heroku so if you guys need any more information let me know.
Edit
I've completed the initializer steps shown here and when I run heroku config:get REDISCLOUD_URL the result is exactly the same as the Redis Cloud URL under the config vars section of my Heroku settings.
Following the documentation, I then set up config/initializers/redis.rb like so:
if ENV["REDISCLOUD_URL"]
$redis = Redis.new(:url => ENV["REDISCLOUD_URL"])
end
Just to check, I tried substituting the actual URL for redis cloud inside the if block instead of just the REDISCLOUD_URL variable but that didn't work. My error message hasn't changed when I try to seed the heroku db.
It’s not enough to just create a $redis variable that points to the installed Redis server, you also need to tell Soulmate about it, otherwise it will default to localhost.
From the Soulmate README you should be able to do something like this in an initializer (instead of your current redis.rb initializer, which you won’t need unless you are using Redis somewhere else in your app):
if ENV["REDISCLOUD_URL"]
Soulmate.redis = ENV["REDISCLOUD_URL"]
end
Looking at the Soulmate source, an easier way may be to set the REDIS_URL environment variable to the Redis url, either instead of or as well as REDISCLOUD_URL, as it looks like Soulmate checks this before falling back to localhost.
Your code is trying to connect to a local Redis instance, instead the one from Redis Cloud - make sure you've completed the initializer step as detailed in order to resolve this.

Is it possible to run locally JRuby on Google App Engine without restarting server on every change?

Unfortunately, GAE requires restart of the server on each code change.
Is it possible to prevent it and have immediate feedback after code save?
Or, can I import Google App Engine's API into my ruby code and run it on Sinatra server? Tried this but it fails on "import com.google.appengine.api" (it doesn't know what 'com' is).
For Sinatra, I use "Rerun" ( http://github.com/alexch/rerun ) which restarts server immediately after a change with minimum wait.
Thanks.
Try http://github.com/rkh/sinatra-reloader
OK, seems like JRuby on Rails doesn't need server restart, Sinatra reloaded/shotgun plugins didn't work well for me.
To run it I copied the files from http://rails-depot.appspot.com/src (the source # http://code.google.com/p/appengine-jruby/source/browse did not contain all the files).

Resources