0

我的应用程序中有一个看起来正确的资源,但是当我打开索引时,我得到一个错误:undefined local variable or method 'new_beta_request_path'. 这beta_request_approval path也发生了。

我的链接看起来像<%= link_to 'New Beta Request', new_beta_request_path, :class => "btn" %><%= link_to "Approve", beta_request_approval_path %>

所有的路径对我来说似乎都是正确的,但显然缺少一些东西......

在我的routes.rb,我有:

resources :beta_requests, :only => [:index, :edit, :create, :update, :destroy]

match '/request_invite', to: 'beta_requests#new', :as => "request_invite"
match 'beta_requests/:id/approve', to: 'beta_requests#approve', :as => "beta_request_approval", :via => :put

当我运行 Rake Routes 时,我得到以下信息:

beta_requests         GET    /beta_requests(.:format)              beta_requests#index
                      POST   /beta_requests(.:format)              beta_requests#create
edit_beta_request     GET    /beta_requests/:id/edit(.:format)     beta_requests#edit
beta_request          PUT    /beta_requests/:id(.:format)          beta_requests#update
                      DELETE /beta_requests/:id(.:format)          beta_requests#destroy
request_invite               /request_invite(.:format)             beta_requests#new
beta_request_approval POST   /beta_requests/:id/approve(.:format)  beta_requests#approve

谁能看到我显然看不到的东西?

4

2 回答 2

0

数组:new中没有?only您可以添加它:

resources :beta_requests, :only => [:index, :edit, :new, :create, :update, :destroy]

或完全删除散列参数,因为这样无论如何都定义了所有资源操作。

于 2012-07-26T02:08:07.150 回答
0

您想在链接中使用request_invite_path而不是。new_beta_request_path那是:

<%= link_to 'New Beta Request', request_invite_path, :class => "btn" %>

这对您可用,因为您在 request_invite 路由定义上设置了 :as 选项。

至于另一个错误,我注意到您的 rake 路由列表beta_request_approval使用 POST 动词,并且您routes.rb使用:via => :put选项定义了该路由。

于 2012-07-26T02:18:04.977 回答