How do you decide where to redirect based on last webpage?

I have two tables, table A has a has_many relationship to table B.

to create an entry in table B, I have a link on the form_page of object A, redirecting to object B’s new page.

I want in the create function of object B to be able to redirect to a different page, based on where the request originated from, i.e. object A’s new page, or object A’s edit page. Is this possible? I saw in the conn object theres a before_send object, but I couldn’t figure out how to use it

It’s possible, but you’d have to save the last path in session - here is a discussion with a sample implementation https://github.com/phoenixframework/phoenix/pull/1402#issuecomment-171088163 and here is a library you can grab (or just add a similar plug) https://github.com/danhper/plug-navigation-history

No! Please do not do this!

This will confuse the user as he opens multiple tabs.

Always provide the “redirect_to” as a (hidden) field in a form or as a parameter in the query string. Also fall back to sensible defaults when it is missing.

I wouldn’t be so sure about it being the only right option :smiley:

Make sure to read mentioned issue, https://github.com/phoenixframework/phoenix/pull/1402#issuecomment-164146348 I just mentioned the result of this discussion.