在Rails中整合凌乱的路由4.如何组织路由而不是将URL指向静态链接?

这里有一个rails nub组织问题:

存在的是什么

一个“Railsy”链接看起来像这样(苗条)

span a href= signout_path 

signout_path对应于AuthController#signout

因此,在我的应用程序中有几种类型的用户 – 消防员,酋长和队长。

每个人都有非常相似的路线:

 /dashboard /dashboard/:date ( this is in case they want to see a previous date; same dashboard, different data in the controller ) /account /account/update /entry/view /entry/edit 

参赛作品可能属于也可能不属于用户。 因为条目应该对任何用户可见(尽管不是相关的操作)

看看我恶心的路线:

 scope :firefighters do get '/dashboard' => 'firefighters#dashboard' get '/dashboard/:date' => 'firefighters#dashboard' get '/account' => 'account#account' post '/account/update' => 'firefighters#account_update' get '/account/change_password' => 'account#change_password' get '/account/change_cell' => 'account#change_cell' get '/account/change_email' => 'account#change_email' get '/account/change_notifications' => 'account#change_notifications' post '/account/update_cell' => 'account#update_cell' # post '/account/update_pass' => 'account#update_pass' # post '/account/update_cell' => 'account#update_cell' # post '/account/update_email' => 'account#update_email' # post '/account/update_notifications' => 'account#update_notifications' # get '/account/change_cell_number' => 'firefighters#account_change_cell_number' # post '/account/request_cell_change' => 'firefighters#account_request_cell_change' # post '/account/update_cell' => 'firefighters#account_update_cell' # get '/account/change_password' => 'firefighters#account_change_pass' # post '/account/update_password' => 'firefighters#account_update_pass' # get '/account/change_email' => 'firefighters#account_change_email' # post '/account/request_email_change' => 'firefighters#account_request_email_change' # post '/account/update_email' => 'firefighters#account_update_email' get '/approve' => 'firefighters#approve' get '/set_tester' => 'firefighters#set_tester' end scope :entries do post '/verify' => 'entries#verify' post '/approve' => 'entries#approve' post '/finalize' => 'entries#finalize' post '/comment' => 'entries#comment' post '/update' => 'entries#update' get '/edit/:entry_id' => 'entries#edit' end 

我使用scope来避免写一百万条路线。 我在resources :entries下移动了Entry路由resources :entries出于这个原因的resources :entries

目前,每个用户类型都有自己的仪表板页面,只是略有不同,只是为了使它工作

现在有一个单独的dashboard.slim account.slimaccount.slim等为消防员,酋长,你得到它。

我多么喜欢这样的事情

我想有一个仪表板来统治它们。 但是,如果您只有一个视图文件,则firefighters_dashboard_path等链接并不十分有用。 我通过为每个用户设置略有不同的仪表板页面来解决此问题。 这似乎是错误的,根本不是干的。

如何组织路线,以便有一个仪表板,根据用户的不同,例如account_path链接会引导消防员的帐户,而不是管理员的帐户?

换句话说,我以队长身份登录,我帐户的链接应该是site.com/account 。 我以管理员身份登录,我的管理链接应该是’site.com/managing’。 在会话中保存“身份”是疯狂的。

这有点需要考虑,为文本墙道歉,但非常感谢帮助。