jefflunt
jefflunt

Reputation: 33954

How do I get the url stored in ":back"?

It's easy, and common, to redirect to :back in Rails.

However, how do I access the actual URL stored, or represented by ":back"?

Upvotes: 0

Views: 1083

Answers (2)

Peter Brown
Peter Brown

Reputation: 51697

Rails uses request.headers["Referer"] and raises an error if it's nil.

Source:

https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/redirecting.rb#L87

Upvotes: 2

roman
roman

Reputation: 11278

request.env['HTTP_REFERER'] in your controller, but be aware, that this can always be nil

Upvotes: 4

Related Questions