迁移到 Rails 3 后,未定义方法“reverse_merge”;对于 nil:NilClass

发布于 2024-11-26 16:18:33 字数 1638 浏览 1 评论 0原文

迁移到 Rails 3 后,我遇到了这个问题

undefined method `reverse_merge' for nil:NilClass

activesupport (3.0.7) lib/active_support/whiny_nil.rb:48:in `method_missing'
actionpack (3.0.7) lib/action_controller/metal/url_for.rb:8:in `url_options'
actionpack (3.0.7) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:195:in `frontend_path'
lib/my_own_login.rb:97:in `login_required'
activesupport (3.0.7) lib/active_support/callbacks.rb:457:in `_run__1711026059__process_action__199225275__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'

还有其他人遇到过这个错误吗?

在 lib/my_own_login.rb:97

if params[:mode].to_i == 1
  redirect_to root_path
else params[:mode].to_i == 2
  redirect_to frontend_path #Line 97
end

在我的 paths.rb 中

match "/account" => "account#index", :via => :get, :as => :frontend

rake routes | grep frontend

frontend GET    /account(.:format)                                                                    {:action=>"index", :controller=>"account"}

After migrate to Rails 3, I have this problem

undefined method `reverse_merge' for nil:NilClass

activesupport (3.0.7) lib/active_support/whiny_nil.rb:48:in `method_missing'
actionpack (3.0.7) lib/action_controller/metal/url_for.rb:8:in `url_options'
actionpack (3.0.7) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:195:in `frontend_path'
lib/my_own_login.rb:97:in `login_required'
activesupport (3.0.7) lib/active_support/callbacks.rb:457:in `_run__1711026059__process_action__199225275__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'

Anyone else encountered this error?

In lib/my_own_login.rb:97

if params[:mode].to_i == 1
  redirect_to root_path
else params[:mode].to_i == 2
  redirect_to frontend_path #Line 97
end

In my routes.rb

match "/account" => "account#index", :via => :get, :as => :frontend

rake routes | grep frontend

frontend GET    /account(.:format)                                                                    {:action=>"index", :controller=>"account"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-12-03 16:18:33

我修复了错误。问题出在以下代码中:

def default_url_options(options={})
  { :org_code => current_organisation.custom_url } if !current_organisation.blank? && !current_organisation.custom_url.blank?
end

我更改为:

def default_url_options(options={})
  if !current_organisation.blank? && !current_organisation.custom_url.blank?
    { :org_code => current_organisation.custom_url }
  else
    {}
  end
end

现在 default_url_options 返回值必须始终散列。

I fixed bug. The problem was in the following code:

def default_url_options(options={})
  { :org_code => current_organisation.custom_url } if !current_organisation.blank? && !current_organisation.custom_url.blank?
end

I changed to:

def default_url_options(options={})
  if !current_organisation.blank? && !current_organisation.custom_url.blank?
    { :org_code => current_organisation.custom_url }
  else
    {}
  end
end

Now default_url_options The return must always hash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文