Rails 与偶尔嵌套路由的多对多关系

发布于 2024-08-27 05:54:45 字数 599 浏览 7 评论 0原文

随着我对 Rails 的了解越来越多,并打破了 ASP.Net 时代的设计思维,今天早上我正在考虑一个场景,但不知道是否可以实现。

治疗师通过服务获得多种治疗 - 反之亦然

在我的控制面板中,我有一个区域供治疗师编辑他们的详细信息(姓名、联系信息等),也可以通过复选框选择他们的治疗。

我想从 Practitioners _form 中删除复选框。拥有自己的表格,我可以这样调用:

<%= link_to "Edit Treatments", edit_practitioner_treatments(@practitioner) %>

但是,从管理的角度来看,我仍然需要能够在没有执业者对象的情况下管理治疗:

<%= link_to "Edit Treatments", edit_treatments(@treatment) %>

这也存在身份验证障碍。

  • 有没有更简单的解决方案来提取我忽略的治疗方法?
  • 是否可以在某些时候使用嵌套路由?
  • 我今天早上是否喝了太多咖啡,因此目前处于精神错乱的状态?

As I am learning more about rails, and breaking my design thinking from ASP.Net days, I was considering a scenario this morning but did not know if it was possible to do.

Practitioners have many Treatments through services - and vice versa

In my control Panel I have an area for Practitioners to edit their details (names, contact info etc) and can also choose their treatments via check-boxes.

I would like to remove the check-boxes from the Practitioners _form. Having their own form which I could call on like this:

<%= link_to "Edit Treatments", edit_practitioner_treatments(@practitioner) %>

However, from an admin point of view I would still need to be able to manage treatments without a practitioner object in sight:

<%= link_to "Edit Treatments", edit_treatments(@treatment) %>

which also has authentication barriers.

  • Is there an easier solution to extract treatments I have overlooked?
  • Is it possible to have nested routes just some of the time?
  • Did I have too much coffe this morning and are therefore currently in a state of insanity?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饭团 2024-09-03 05:54:45

一般来说,在考虑管理功能时,通常会向用户提供完全不同的界面,其权限检查更多地基于“这会破坏某些东西”而不是“是否应该允许”,因此创建一个具有单独控制器的管理区域是有利的。例如:

map.namespace :admin do |admin|
  # Admin::PracticionersController
  map.resources :practicioners

  # Admin::TreatmentsController
  map.resources :treatments
end

map.resources :practicioners do |practicioner|
  practicioner.resources :treatments
end

map.resources :treatments do |treatment|
  treatment.resources :practicioners
end

所有 Admin::* 控制器都可以从 Admin::BaseController 等继承,在允许执行任何操作之前执行足够严格的身份验证检查。

在我见过的大多数应用程序中,面向用户的前端都有设计或风格元素,它们的布局通常被导航元素、广告或其他编辑内容包围。创建一个整洁的单独管理视图,每页显示更多信息,并允许对不向用户公开的维度进行排序或搜索,在管理中等规模的数据集时非常有价值。

尽管制作这些额外的管理控制器及其关联表单似乎需要做很多工作,但如果您仔细设计,您可以回收两个区域之间的许多功能,尤其是页面部分。

Generally when considering admin functions, which often present an entirely different interface to the user with permission checking based more on "will this break something" than "should you be allowed", it is advantageous to create an admin area with separate controllers. For example:

map.namespace :admin do |admin|
  # Admin::PracticionersController
  map.resources :practicioners

  # Admin::TreatmentsController
  map.resources :treatments
end

map.resources :practicioners do |practicioner|
  practicioner.resources :treatments
end

map.resources :treatments do |treatment|
  treatment.resources :practicioners
end

All Admin::* controllers can inherit from something such as Admin::BaseController that performs sufficiently rigorous authentication checking before allowing any actions to be performed.

In most applications I've seen, the user-facing front-end has an element of design or style to it, where they layout is often hemmed in by navigational elements, advertising, or other editorial content. Creating a separate admin view that's uncluttered, shows far more information per page, and allows sorting or searching on dimensions not exposed to the user is very valuable when managing even medium-sized sets of data.

Although it might seem like a lot of work to make these extra admin controllers and their associated forms, if you are careful in your design, you can recycle a lot of the functionality between the two areas, especially page partials.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文