Ruby on rails rails通过url传输多态对象的方法

Ruby on rails rails通过url传输多态对象的方法,ruby-on-rails,polymorphism,Ruby On Rails,Polymorphism,如何将多态对象传递给另一个控制器 例如,从邮件重定向/1/ 发送请求/新建?对象类型=消息和对象id=1 或者,第二个示例,来自文件/154/ 发送请求/新建?对象类型=文件和对象id=154 是 对吧? 请求模型具有 belongs_to :object , :polymorphic => true 嵌套路线,例如: messages/1/requests/new files/154/requests/new redirect_to new_comments_reque

如何将多态对象传递给另一个控制器

例如,从邮件重定向/1/

发送请求/新建?对象类型=消息和对象id=1

或者,第二个示例,来自文件/154/

发送请求/新建?对象类型=文件和对象id=154

对吧?

请求模型具有

  belongs_to      :object , :polymorphic => true

嵌套路线,例如:

messages/1/requests/new
files/154/requests/new

redirect_to new_comments_request_path(Comment.find(1))

感谢您提供有关嵌套路由的信息。在我的例子中,所有多态对象,如消息、文件、注释等,都以相同的方法重定向。有没有办法单独使用“new_request_path(@polymorphicobject)”之类的东西,而不是“new_comments_request_path”、“new_messages_request_path”等?你可以使用,如果你使用它,有一个url助手“new_resource_url”-我想这就是你要找的。
messages/1/requests/new
files/154/requests/new

redirect_to new_comments_request_path(Comment.find(1))