【问题标题】:Error After Switching Rails App to Postgres - ActiveSupport::SafeBuffer将 Rails 应用程序切换到 Postgres 后出错 - ActiveSupport::SafeBuffer
【发布时间】:2012-12-05 15:52:15
【问题描述】:

我是编程和 Rails 的新手,所以请原谅任何重大疏忽。我最近将一个 rails 应用程序部署到 heroku 并将所有环境切换到我的数据库的 postgres。 Heroku 在 Postgres 上工作得很好——运行 rake db:drop db:migrate db:create db:seed all 用 rake 任务填充我的数据库,测试了应用程序搜索表单、过滤器、数据查询等。一切都很好。

但我现在在启动本地服务器并转到我的两个具有排序的视图后,在浏览器中收到一条错误消息,显示“ActiveSupport::SafeBuffer 与 nil 的比较失败” - 浏览器将我指向一个在具有

的视图中的行
<% @price_array.sort! {|x,y| x <=> y} %>

这是我在服务器日志中看到的:

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'

这可能与我遇到的问题有关 - 我似乎无法删除我的 postgres 数据库。

这是我在终端中使用 postgres 看到的:

postgres=# \dbdrop postgres
List of tablespaces
Name | Owner | Location 
------+-------+----------
(0 rows)

我昨晚做的另一件事是按照此处找到的说明更新我的 .bash_profile (http://stackoverflow.com/questions/6770649/repairing-postgresql-after-upgrading-to-osx-10-7-lion )。这就是我的 .bash_profile 现在的样子:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

PATH=/usr/local/bin:$PATH

postgres 中是否有一些我遗漏的配置导致此错误?任何帮助或资源将不胜感激。谢谢。

【问题讨论】:

    标签: ruby-on-rails postgresql activesupport


    【解决方案1】:

    您的 a 数组中有 nil 值。试试看:

     a.compact.sort
    

    compact 删除数组中所有出现的 nil。

    【讨论】:

    • 谢谢 - 成功了。很好奇为什么它可以工作一段时间,一定是在我以前没有的地方汇总的数据中得到了零。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    相关资源
    最近更新 更多