I've been looking around for this but can't seem to find a solution for what I'm trying to do.
I have a 'thankyou' view routed from the custom controller action. I want to restrict access to this view to only the case where the user came from the view where the user submitted the form since I don't want users to be able to navigate directly to this view.
How would I write the controller code to accomplish this in the custom controller action?
In your controller you can do:
def thankyou
if request.referrer != "http://mysite.com/myformpage"
redirect_to root_path, notice: "Invalid access"
end
end
Or you can create a before_filter for this action with the same logic
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.