unicorn fails when started by capistrano - ruby-on-rails

When I start unicorn via capistrano task and try to access my app I get this
tarted GET "/" for xx.xxx.xxx at 2012-08-11 01:38:31 +0000
Processing by HomeController#index as HTML
Rendered home/index.html.erb within layouts/application (0.1ms)
Completed 500 Internal Server Error in 87ms
** [Bugsnag] No API key configured, couldn't notify
ActionView::Template::Error (undefined method `split' for nil:NilClass):
32: </form>
33: </ul>
34: <ul class="nav pull-right">
35: <% if user_signed_in? %>
36: <li class="dropdown">
37: <a href="#" class="dropdown-toggle" data-toggle="dropdown">
38: <%= current_user.name %>
app/controllers/application_controller.rb:5:in `current_user'
app/controllers/application_controller.rb:9:in `user_signed_in?'
app/views/layouts/application.html.erb:35:in `_app_views_layouts_application_html_erb__3931886679734892787_26070680'
in addition of ActionView::Template::Error, unicorn says that no busgnag API key configured, but I've already set the key on my root's .bashrc and deploy's .bashrc (deploy is a user too)
but when I access the server via ssh like ssh root#server and try to start unicorn with the same command the capistrano's task issued, everythin works fine...
I've tried to set root user on capistrano and deploy user, both with use_sudo true and false...
What am I missing here?
Thanks

Are you sure when you run it manually you are running in production mode? undefined methodxxxx' for nil:NilClass` happens when you have an nil variable. Often times code like...
Articles.each do |article|
article.title
end
Will fails with the same error because the db is populated differently in each environment. I would suggest looking at line 5 application_controller.rb and seeing if that variable is present in both production and development.
Also, make sure that your bugsnap api key is available in your production.rb file.

Related

haml file seems causing HTTP ERROR 500 ruby on rails6 at Heroku

I'm upgrading ruby, rails and the other gems of an old application built on ruby2 running on Heroku.
I made it to deploy to Heroku but HTTP ERROR 500 occurs.
the error log is this below
ActionView::Template::Error (login.js):
40: = image_tag "app_logo.png", id: "app_logo", alt: "app"
41:
42: %span#dest
43: = javascript_include_tag "login"
app/views/sessions/_login.html.haml:43
app/views/sessions/login.html.haml:1
When I commented out this part = javascript_include_tag "login"
no error is emitted but also nothing appeared on the application page.
If anyone have any idea to solve it share with me please.
thanks
Your HAML code can be translated like this :
%span#dest
= javascript_include_tag "login"
<span id="dest">
<script src="/assets/login.js"></script>
</span>
The error means that your application failed to load the /assets/login.js.
You should look there what have messed up.

Redmine Plugin trashed by errant flash statement

I accidentally put a bad flash statement in my Redmine Plugin, and now my entire Redmine is trashed. No matter what I do, I get the following invincible error message:
ActionView::Template::Error (undefined method `html_safe' for
:value:Symbol):
54: <div id="sidebar">
55: <%= yield :sidebar %>
56: <%= view_layouts_base_sidebar_hook_response %>
57: </div>
58:
59: <div id="content">
60: <%= render_flash_messages %> app/helpers/application_helper.rb:316:in `block in
render_flash_messages' app/helpers/application_helper.rb:315:in
`render_flash_messages' app/views/layouts/base.html.erb:57:in
`_app_views_layouts_base_html_erb__1290735862753404915_23873920'
Fortunately, this exact problem has happened before
Unfortunately, none of the solutions proposed work for me, even though they worked for the guy who asked that question.
I generated a new secret key with the following command, taken straight from the Redmine tutorial:
bundle exec rake generate_secret_token
I restart the WEBrick server -- to no avail. I played around with the mentioned "rescue" item, but couldn't really figure out how to make it work.
Does anyone know how to fix this devastating bug?
FYI -- manually changing the key in:
config/initializers/secret_token.rb
slayed this deadly error

Heroku can't find user but works in dev

I'm hitting a problem with my heroku deployment. Here is the log:
2014-04-29T16:41:59.782999+00:00 app[web.1]: Started GET "/lines/33/edit" for 94.174.113.168 at 2014-04-29 16:41:59 +0000
2014-04-29T16:41:59.782933+00:00 app[web.1]: Started GET "/lines/33/edit" for 94.174.113.168 at 2014-04-29 16:41:59 +0000
2014-04-29T16:41:59.804819+00:00 app[web.1]:
2014-04-29T16:41:59.804823+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find User with id=0):
2014-04-29T16:41:59.804826+00:00 app[web.1]: app/views/lines/_history.html.erb:7:in `block in _app_views_lines__history_html_erb__3033746240219592358_69949428301200'
2014-04-29T16:41:59.804824+00:00 app[web.1]: config/initializers/paper_trail.rb:4:in `user'
2014-04-29T16:41:59.804854+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `_app_views_lines__history_html_erb__3033746240219592358_69949428301200'
2014-04-29T16:41:59.804828+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `each'
2014-04-29T16:41:59.804856+00:00 app[web.1]: app/views/lines/edit.html.erb:16:in `_app_views_lines_edit_html_erb__4129892984524241027_69949427894700'
2014-04-29T16:41:59.804869+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `each'
2014-04-29T16:41:59.804871+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `_app_views_lines__history_html_erb__3033746240219592358_69949428301200'
2014-04-29T16:41:59.804872+00:00 app[web.1]: app/views/lines/edit.html.erb:16:in `_app_views_lines_edit_html_erb__4129892984524241027_69949427894700'
2014-04-29T16:41:59.804875+00:00 app[web.1]:
2014-04-29T16:41:59.804874+00:00 app[web.1]:
2014-04-29T16:41:59.804857+00:00 app[web.1]:
2014-04-29T16:41:59.804858+00:00 app[web.1]:
2014-04-29T16:41:59.804864+00:00 app[web.1]:
2014-04-29T16:41:59.804865+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find User with id=0):
2014-04-29T16:41:59.804866+00:00 app[web.1]: config/initializers/paper_trail.rb:4:in `user'
2014-04-29T16:41:59.804868+00:00 app[web.1]: app/views/lines/_history.html.erb:7:in `block in _app_views_lines__history_html_erb__3033746240219592358_69949428301200'
The offending initializer is as follows:
module PaperTrail
class Version < ActiveRecord::Base
def user
User.find self.whodunnit.to_i
end
def nextversion
self.next
end
end
end
Which is getting called in the _history view with the following:
<%= gravatar_for version.user %><%= link_to version.user.username, user_path(version.user) %>
This works fine in development and appears to work fine in production on most edit pages but on one I am encountering this error. I wanted to check the version in the console but it seems I can't access paper_trail Versions in the console at all, I can only assume this is because I don't have a Version model, only a table and a controller.
How can I fix this?
You are getting following error
ActiveRecord::RecordNotFound (Couldn't find User with id=0)
on the following method
def user
puts "Value of whodunnit is -----------> #{self.whodunnit}"
User.find self.whodunnit.to_i
end
which is called in
<%= gravatar_for version.user %><%= link_to version.user.username, user_path(version.user) %>
because self.whodunnit.to_i is returning 0. That means, whodunnit is either "" or nil or 0. Please set the correct value of whodunnit attribute. Also, you can check the current value of whodunnit by adding a logger or puts statement in PaperTrail::Version# user method.
You probably did not ran your seed.rb file (heroku run rake db:seed) to create the user or you just are looking for an user that is not defined anymore (like deleted for example).
When you delete a user that had id=0 the next user will have id=1.
Just for sure, o recommend that you enter on your console (heroku run console) and try to find it by yourself (Client.find(0)) or try to list all of them (Client.all) to see if the user with id=0 is defined.
Hope it helps

Error After Switching Rails App to Postgres - ActiveSupport::SafeBuffer

I'm new to programming and rails so please forgive any big oversights. I recently deployed a rails app to heroku and switched all environments to postgres for my db. It is up on heroku working just fine with Postgres - ran rake db:drop db:migrate db:create db:seed all to populate my database with a rake task, tested the apps search forms, filters, data queries, etc. and it all worked well.
But I am now getting an error that says "comparison of ActiveSupport::SafeBuffer with nil failed" in the browser after firing up my local server and going to two of my views that have sorts - the browser is pointing me to a line in a view that has
<% #price_array.sort! {|x,y| x <=> y} %>
This is what I see in the server log:
Rendered skis/index.html.erb within layouts/application (212.9ms)
Completed 500 Internal Server Error in 280ms
ActionView::Template::Error (comparison of ActiveSupport::SafeBuffer with nil failed):
51: <% ski.inventories.each do |inventory| %>
52: <% a.push(number_to_currency(inventory.price)) %>
53: <% end %>
54: <% #lowest_price = a.sort { |x,y| x <=> y} %>
55: from <%= #lowest_price.first %>
56: </br>
57: </li>
app/views/skis/index.html.erb:54:in `sort'
app/views/skis/index.html.erb:54:in `block in_app_views_skis_index_html_erb___2303745325449705978_70146899313600'
app/views/skis/index.html.erb:32:in `each'
app/views/skis/index.html.erb:32:in `_app_views_skis_index_html_erb___2303745325449705978_70146899313600'
app/controllers/skis_controller.rb:32:in `index'
This may be related to the issue I am in running into - I cannot seem to drop my postgres database.
This is what I'm seeing in the terminal with postgres:
postgres=# \dbdrop postgres
List of tablespaces
Name | Owner | Location
------+-------+----------
(0 rows)
One other thing I did last night was update my .bash_profile per the instructions found here (http://stackoverflow.com/questions/6770649/repairing-postgresql-after-upgrading-to-osx-10-7-lion). This is what my .bash_profile looks like now:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
PATH=/usr/local/bin:$PATH
Is there some configuration in postgres that I am missing that is causing this error? Any help or resources would be appreciated. Thanks.
you have nil values in your a array. Try :
a.compact.sort
compact removes all occurences of nil in your array.

Heroku Template Error - looking for partials in the wrong directory

So I'm learning Rails and working through Michael Hartl's tutorial.
When I deploy to Heroku, I get the infamous "We're sorry but something went wrong."
The app runs just fine on the local development server.
Heroku logs say:
2012-06-27T15:31:47+00:00 app[web.1]: Completed 500 Internal Server Error in 112ms
2012-06-27T15:31:47+00:00 app[web.1]:
2012-06-27T15:31:47+00:00 app[web.1]: * "/app/app/views"
2012-06-27T15:31:47+00:00 app[web.1]: ActionView::Template::Error (Missing partial layouts/header with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
2012-06-27T15:31:47+00:00 app[web.1]: ):
2012-06-27T15:31:47+00:00 app[web.1]: 11: </head>
2012-06-27T15:31:47+00:00 app[web.1]: 12: <body>
2012-06-27T15:31:47+00:00 app[web.1]: 13:
2012-06-27T15:31:47+00:00 app[web.1]: 14: <%= render 'layouts/header' %>
2012-06-27T15:31:47+00:00 app[web.1]: 15:
2012-06-27T15:31:47+00:00 app[web.1]: 16: <div class="container">
2012-06-27T15:31:47+00:00 app[web.1]: app/views/layouts/application.html.erb:14:in `_app_views_layouts_application_html_erb__112987114114249875_31386580'
2012-06-27T15:31:47+00:00 app[web.1]: 17: <% flash.each do |key, value| %>
If I'm reading this correctly, it's looking in /app/app/views for the header partial. This is wrong - it should be in /app/views.
On my development machine a file _header.html.erb is in app/views/layouts.
So why did Heroku add the extra app directory?
I had the same issue when I realized my mistake: I did git commit -am "commit_message", omitting git add . before it which resulted in leaving the new files out of the commit.
According to git help commit:
-a, --all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about
are not affected.
After adding the untracked files, new commit and git push heroku master it worked.
I just had this error and it's because the partial file was haml, but my Gemfile had haml as in development group only.
I converted to Slim, which I use for all the rest of the app, and that was it.
So basically, the server couldn't find the file because it had an unsupported extension (which was somehow available in development env).

Resources