Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 神秘的AbstractController::ActionNotFound(路径在那里)_Ruby On Rails_Ruby On Rails 3_Mongoid - Fatal编程技术网

Ruby on rails 神秘的AbstractController::ActionNotFound(路径在那里)

Ruby on rails 神秘的AbstractController::ActionNotFound(路径在那里),ruby-on-rails,ruby-on-rails-3,mongoid,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路由显

(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路由
显示此路由:

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::billingsubscriptioncontroller
)具有方法
add\u addon

我写了一篇日志中类似的帖子:

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就是动作?希望我只是错过了一些明显的东西

我从rails版本猜测,您遇到了与此类似的问题:这是rails 3中的一个bug,请注意注释:

您需要替换:

  member do
    post :add_addon
  end
比如说:

match "add_addon" => "billing_subscriptions#add_addon", :as => :add_addon, :via => :post
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
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
您将得到一个稍微交换的路径,如下所示:
admin\u campus\u hub\u billing\u subscription\u add\u addon\u path
,但它应该在rails 3和4中工作

总的来说是这样的:

match "add_addon" => "billing_subscriptions#add_addon", :as => :add_addon, :via => :post
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
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
请注意,完整的rake路由如下所示:

match "add_addon" => "billing_subscriptions#add_addon", :as => :add_addon, :via => :post
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
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

是的,编辑/更新路由工作正常。解决方法是将路由的动词定义为GET,而不是POST/DELETE。然后它就开始工作了。你能在回答中省略你的代码吗?你可以把
帖子:add\u addon
改为
get:add\u addon
。这不是答案。这是一个解决办法。我仍在寻找答案。出于好奇,您能否将其更改为仅
post:add_on
,而不使用成员块?您仍然可以访问参数,只是前缀不同而已。