How to add a custom RESTful route to a Rails app?

后端 未结 4 1299
既然无缘
既然无缘 2021-01-30 01:47

I\'m reading these two pages

  1. resources
  2. Adding more RESTful actions

The Rails Guides page shows

map.resources :photos, :new          


        
4条回答
  •  死守一世寂寞
    2021-01-30 02:40

    This can be taken as just another syntax -- something good to know may be.

    Syntax 1:

    resources :users do
      member do
        get 'signup'
        post 'register'
      end
    end
    

    Rake Route Output will include

    signup_users GET    /users/signup(.:format)    {:action=>"signup", :controller=>"users"}
    register_users POST   /users/register(.:format)  {:action=>"register", :controller=>"use
    

    rs"}

    Syntax 2: If you have only one collection route

    resources :users do
        get 'signup', :on => :collection
    end
    

提交回复
热议问题