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.
Related
in my application_layout.html.rb of my rails application I'm loading controller specific javascript:
<%= javascript_include_tag params[:controller] if Rails.application.assets_manifest.find_sources("#{params[:controller]}.js").any? %>
Which is working correctly until I deploy to Heroku. Than I get this error:
ActionView::Template::Error (undefined method `find_asset' for nil:NilClass)
The same error I get when I try to call any method on the object returned from #find_sources.
EDIT:
<%= Rails.application.assets_manifest.find_sources("#{params[:controller]}.js") %>
returns #<Enumerator:0x007fda655a17b0>
Any idea?
Thanks
It does not work because there is a static manifest file in production and no in development (usually, it depends on environment config). You can create a helper method to do the check differently based on current environment configuration:
def asset_exist?(path)
if Rails.configuration.assets.compile
Rails.application.precompiled_assets.include? path
else
Rails.application.assets_manifest.assets[path].present?
end
end
Please check this issue for more details.
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
I am following Michael Hartl's Ruby on Rails tutorial (9.2)
http://www.railstutorial.org/book/updating_and_deleting_users#cha-updating_showing_and_deleting_users
and I am getting this error.
I am getting this error here
undefined method `each' for nil:NilClass
<h1>All users</h1>
<ul class="users">
<% #users.each do |user| %>
<li>
<%= gravatar_for user, size: 52 %>
<%= link_to user.name, user %>
I created 100 users using gem 'faker', '1.1.2'. I am not sure why there are nil users when I've just created 100 of them.
I also ran these commands
bundle exec rake db:reset
bundle exec rake db:populate
bundle exec rake test:prepare
The problem is NOT that you don't have any users. If you had no users, #users would be an empty array and the .each method would work happily (although there would be nothing to iterate over)
So the problem is that #users is not being initialized correctly.
Look at listing 9.23 on the page you referenced. Do you have this code in your controller?
def index
#users = User.all
end
That's likely what's missing.
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.
Yes, I've read this.
This is what I'm getting in my production.log:
ActionView::TemplateError (undefined method `password' for #<User:0x2b0ddb58cdc0>) on line #11 of app/views/users/new.html.erb:
8: </p>
9: <p>
10: <%= f.label :password, "Password:" %><br />
11: <%= f.password_field :password %>
12: </p>
13: <p>
14: <%= f.label :password_confirmation, "Password again:" %><br />
When I try:
$ heroku rake db:reset RAILS_ENV=production
I get:
yeqynzfiku already exists
(in /disk1/home/slugs/109616_e6df6f2_8837/mnt)
Couldn't drop yeqynzfiku : #<ActiveRecord::StatementInvalid: PGError: ERROR: must be owner of database yeqynzfiku
: DROP DATABASE IF EXISTS "yeqynzfiku">
I don't know what this means. I've also tried
$ heroku rake db:reset
$ heroku rake db:migrate RAILS_ENV=production
$ heroku rake db:migrate
$ heroku rake gems:install (for what it's worth)
Everything works fine locally, both in development and production modes. I have a .gems file in my app, and when I first pushed to Heroku it seemed to install AuthLogic and Paperclip just fine.
Stumped. Thanks.
Sounds like you solved it, but with problems like this I find it handy do do a heroku restart.
For example, after running migrations with heroku rake db:migrate the app needs to be restarted before it will see those new columns.
Instead of db:reset try db:migrate VERSION=0 and db:migrate.
I think they have issues with reset because it tries to drop the db.
Also, you don't need to put RAILS_ENV=production it's the default AFAIK...
I had the same problem. I did a heroku restart and it worked perfectly.
Ah, had something to do with lots of things in the .gitignore file. Should have cleared it before pushing to Heroku.