简体   繁体   English

从引擎内重定向到父Rails应用程序的路由

[英]redirect to parent Rails app's route from within engine

So I have a Rails engine contained within a Rails app. 所以我在Rails应用程序中包含一个Rails引擎。 I want to do something like redirect_to @record.polymorphic_relationship in one of my engine's controllers, where @record.polymorphic_relationship is a Picture , which is a model in the parent app. 我想在我的一个引擎控制器中执行redirect_to @record.polymorphic_relationship之类的操作,其中@record.polymorphic_relationship是一个Picture ,它是父应用程序中的模型。 There's a picture_path path helper in the parent Rails app. 父Rails应用程序中有一个picture_path路径助手。

I feel like I ought to be able to redirect from within the engine to a route in the parent app using main_app somehow. 我觉得我应该能够以某种方式使用main_app从引擎内重定向到父应用程序中的main_app Just doing redirect_to @record.polymorphic_relationship inside an engine controller doesn't work, because it complains no picture_url route exists. 只是在引擎控制器内执行redirect_to @record.polymorphic_relationship不起作用,因为它抱怨没有picture_url路由存在。 This same code works from within a controller in the parent app. 此相同的代码在父应用程序的控制器内工作。

If I do redirect_to main_app.send("#{@record.polymorphic_relationship_type.downcase}_path", @record.polymorphic_relationship) , it works, but this seems hacky. 如果我执行redirect_to main_app.send("#{@record.polymorphic_relationship_type.downcase}_path", @record.polymorphic_relationship) ,它可以工作,但这看起来很糟糕。 Is there a better way of doing this? 有没有更好的方法呢?

redirect_to main_app.url_for(@record.polymorphic_relationship)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM