[英]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.