Rails REST routing: dots in the resource item ID

前端 未结 3 1362
清歌不尽
清歌不尽 2020-12-15 20:30

I have following in my routes.rb:

resources :users, :except => [:new, :create] do
    get \'friends\', :as => :friends, :on => :member, :to => \"         


        
3条回答
  •  鱼传尺愫
    2020-12-15 20:52

    The following constrain definition permit the dot in id as well as any character except slash.

    Supported formats must be explicitly defined (here .html and .json) to not to be taken by id.

    resources :foobars,
      :constraints => { :id => /[^\/]+(?=\.html\z|\.json\z)|[^\/]+/ }
    

    That constrain definition is worked with Rails 3.1

    For earlier Rails versions you may need to backport look-ahead support in regin gem (it is vendored in rack-mount gem)

提交回复
热议问题