导轨 - 一个表中的多个模型(视图)。如何根据模型创建重定向以编辑?
我有一个问题:在项目中,我组合了大多数不同的模型(例如人,画廊,文章...),以便在表中的一个视图中显示它们的共同列表。 现在,在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
orhttp://localhost:3000/en/persons/3/edit
What is the best option for solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Use the polymorphic routing helpers: