简体   繁体   中英

Dynamic Routing in Rails for landing page

I currently have this in my routes.rb

get 'admin', to: 'admin/appointments#index'

I want the route to be dynamic based on the user that logs in. But I can't do it like this, where should I set this?

get 'admin', to: @current_admin.landing_page

It sounds like you're trying to introduce Controller logic into your routes. You probably want one admin_landing_page route, to which you supply current user as a parameter.

So in your Routes, you want something like this

get 'admin', to: landing_page/:admin_identifier

And in your controller

@current_admin = YourAdminModel.find(params:[:admin_identifer])

Then you can use @current_admin in your view to customize it based on data from the current_admin, such as

<h1>Welcome to the homepage of Admin <%= @current_admin.name %>!</h1>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM