我想获得一个带有以下地址的页面: http://localhost:3000/admin/users/1/check_user_restart_passes/1/check_restart_passs_weeks,但我不知道如何配置路由
我的routes.rb
文件:
namespace :admin do
get "/:admin_user_id/dashboard", to: "admin_dashboard#index", as: :admin_dashboard
resources :admin_users, except: [:show]
resources :users, only: [:index, :edit, :update, :destroy, :show, :check_pass] do
member do
get "check_user_restart_passes"
get "check_user_restart_pass_weeks"
end
end
我的控制器:
class Admin::UsersController < Admin::AdminsController
def check_user_restart_pass_weeks
@user = User.find(params[:id])
@user_restart_pass_weeks = UserRestartPassWeek.where("user_id = ?", @user.id)
end
def check_user_restart_passes
@user = User.find(params[:id])
@user_restart_passes = UserRestartPass.where("user_id = ?", @user.id)
end
end
答案 0 :(得分:2)
map
这将产生以下路线:
namespace :admin do
get "/:admin_user_id/dashboard", to: "admin_dashboard#index", as: :admin_dashboard
resources :admin_users, except: [:show]
resources :users, only: [:index, :edit, :update, :destroy, :show, :check_pass] do
resources :check_user_restart_passes, only: :show do
get "check_user_restart_pass_weeks"
end
end
end