rails 路线的模板选项

大流氓

假设我的routes.rb文件中有以下内容

json_request_only = {
  defaults:    { format: :json }, 
  constraints: { format: :json }
}

ajax_server = {
  only: [:create, :destroy]
}.merge(json_request_only)

Rails.application.routes.draw do

  root to: 'home#index'

  get 'contact/us/:section', to: 'home#contactus', as: 'contact_us'

  resources :uploaded_files, ajax_server

  # only to create/delete shopping carts and only excepts JSON format
  resources :shopping_carts, ajax_server

  resources :item_types, :path => "category", json_request_only do
    member do 
      delete :delete_image
      delete :archive
      patch :recover
    end
  end
end

我收到以下错误

意外的keyword_do_block,期待=> ategory”,json_request_only 做
                                                                       ^

我正在尝试做的是在路由中使用一些模板选项。

问题:

我该如何解决这个问题?

眼花缭乱

我很确定你将不得不合并这样的选项

resources :item_types, json_request_only.merge(path: "category") do

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章