导轨 - 一个表中的多个模型(视图)。如何根据模型创建重定向以编辑?

发布于 2025-01-27 12:11:38 字数 769 浏览 3 评论 0原文

我有一个问题:在项目中,我组合了大多数不同的模型(例如人,画廊,文章...),以便在表中的一个视图中显示它们的共同列表。 现在,在HAML中,我想添加编辑操作:对于每个条目,并将其重定向到适当的模型。

我想要这样的东西:

- @searches.each do |p|
  = link_to 'EDIT', edit_SOME_MODEL_path(p), class: 'a__link-btn'

因此,它可以是很多型号:

= link_to 'EDIT', edit_person_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_news_article_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_order_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_news_article_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_movie_path(p), class: 'a__link-btn'

当我单击选定的模型时,我想根据模型来重定向,例如: http:// localhost:3000/en news_articles/2/edit 或者 http:// localhost:3000/en/persons/3/edit

解决方案的最佳选择是什么?

I have this problem: In the project I combined most of the different models (eg Person, Gallery, Article ...) so that their common list is displayed in one view in the table.
Now, in haml I want to add edit actions: for each entry and make it redirect to the appropriate model.

I want something like this:

- @searches.each do |p|
  = link_to 'EDIT', edit_SOME_MODEL_path(p), class: 'a__link-btn'

So, It can be a lot of models:

= link_to 'EDIT', edit_person_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_news_article_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_order_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_news_article_path(p), class: 'a__link-btn'
= link_to 'EDIT', edit_movie_path(p), class: 'a__link-btn'

And when I click on the selected one, I want to be redirected depending on the model e.g.:
http://localhost:3000/en/news_articles/2/edit
or
http://localhost:3000/en/persons/3/edit

What is the best option for solution?

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

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

发布评论

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

评论(1

九八野马 2025-02-03 12:11:38

使用

- @searches.each do |p| 
  = link_to 'EDIT', [p, :edit], class: 'a__link-btn'

Use the polymorphic routing helpers:

- @searches.each do |p| 
  = link_to 'EDIT', [p, :edit], class: 'a__link-btn'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文