神秘的AbstractController :: ActionNotFound(路线在那里)

时间:2012-07-17 18:35:29

标签: ruby-on-rails ruby-on-rails-3 mongoid

(Rails 3.0.7)

我的routes.rb有这个:

namespace :admin do
  namespace :campus_hub do
    resources :billing_subscriptions, {
      :except => [:destroy, :new, :create]
    } do
      member do
        post :add_addon
      end
    end
  end
end

rake routes显示了这条路线:

add_addon_admin_campus_hub_billing_subscription POST   /admin/campus_hub/billing_subscriptions/:id/add_addon(.:format)                            {:action=>"add_addon", :controller=>"admin/campus_hub/billing_subscriptions"}

我的控制器(Admin::CampusHub::BillingSubscriptionsController)的方法为add_addon

我在日志中执行了这样的POST:

Started POST "/admin/campus_hub/billing_subscriptions/50059f5be628f83b13000012/add_addon" for 33.33.33.1 at Tue Jul 17 20:21:17 +0200 2012

我收到了这个错误:

AbstractController::ActionNotFound (The action '50059f5be628f83b13000012' could not be found for Admin::CampusHub::BillingSubscriptionsController)

我完全不知所措。我发出的POST请求与路由完全匹配。为什么认为ID是动作?希望我只是遗漏了一些明显的东西!

1 个答案:

答案 0 :(得分:0)

我从rails版本中猜到你遇到了类似的问题:Routing error with Rails 3 with members这是rails 3中的一个错误,请注释:Routing error with Rails 3 with members

您需要替换:

  member do
    post :add_addon
  end

有这样的事情:

match "add_addon" => "billing_subscriptions#add_addon", :as => :add_addon, :via => :post

你得到一个像这样的稍微交换的路径:admin_campus_hub_billing_subscription_add_addon_path但是它应该在第3和第4轨中工作。

所有这些都是这样的:

namespace :admin do
  namespace :campus_hub do
    resources :billing_subscriptions, {
      :except => [:destroy, :new, :create]
    } do
      match "add_addon" => "billing_subscriptions#add_addon", :as => :add_addon, :via => :post
    end
  end
end

请注意,完整的rake路线如下所示:

admin_campus_hub_billing_subscription_add_addon POST  /admin/campus_hub/billing_subscriptions/:billing_subscription_id/add_addon(.:format) admin/campus_hub/billing_subscriptions#add_addon