Sarah Vessels
Sarah Vessels

Reputation: 31640

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?

Upvotes: 4

Views: 1357

Answers (1)

cgat
cgat

Reputation: 3909

redirect_to main_app.url_for(@record.polymorphic_relationship)

Upvotes: 6

Related Questions