简体   繁体   中英

redirect to parent Rails app's route from within engine

So I have a Rails engine contained within a Rails app. 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. There's a picture_path path helper in the parent Rails app.

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. Just doing redirect_to @record.polymorphic_relationship inside an engine controller doesn't work, because it complains no picture_url route exists. 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. Is there a better way of doing this?

redirect_to main_app.url_for(@record.polymorphic_relationship)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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