相关疑难解决方法(0)

Rails路由:嵌套,成员,集合,命名空间,范​​围和可自定义

我想了解更多有关Rails路由的信息.

会员和收藏

  # Example resource route with options:
     resources :products do
       member do
         get 'short'
         post 'toggle'
       end

       collection do
         get 'sold'
       end
     end
Run Code Online (Sandbox Code Playgroud)

命名空间和范围

  # Example resource route within a namespace:
     namespace :admin do
       resources :products
     end

     scope :admin do
       resources :products
     end
Run Code Online (Sandbox Code Playgroud)

约束,Redirect_to

# Example resource route with options:
 get "/questions", to: redirect {|params, req| 
     begin
       id = req.params[:category_id]
       cat = Category.find(id)
       "/abc/#{cat.slug}"
     rescue
       "/questions"
     end
 }
Run Code Online (Sandbox Code Playgroud)

定制:

resources :profiles
Run Code Online (Sandbox Code Playgroud)

来自resource profiles编辑的原始网址.

http://localhost:3000/profiles/1/edit
Run Code Online (Sandbox Code Playgroud)

我想为只有点击的用户提供它,edit profile …

ruby routing routes ruby-on-rails ruby-on-rails-4

6
推荐指数
1
解决办法
6943
查看次数

标签 统计

routes ×1

routing ×1

ruby ×1

ruby-on-rails ×1

ruby-on-rails-4 ×1