我的应用程序中有一个资源似乎是正确的但是当我打开索引时,我收到一个错误: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
任何人都能看到我显然无法看到的东西吗?
答案 0 :(得分:0)
:new
数组中没有only
?您可以添加它:
resources :beta_requests, :only => [:index, :edit, :new, :create, :update, :destroy]
或完全删除哈希参数,因为这样就可以定义所有资源操作。
答案 1 :(得分:0)
您希望在链接中使用request_invite_path
代替new_beta_request_path
。那就是:
<%= link_to 'New Beta Request', request_invite_path, :class => "btn" %>
您可以使用此功能,因为您在request_invite路由定义中设置了:as选项。
至于其他错误,我注意到您的佣金路线列出beta_request_approval
使用POST动词,routes.rb
使用:via => :put
选项定义该路线。