I want to be sure that the data I receive came from a specific page (it's for a navigator game).
I would prefer a solution using RoR but if we can do it with JS it's ok =)
I want to be sure that the data I receive came from a specific page (it's for a navigator game).
I would prefer a solution using RoR but if we can do it with JS it's ok =)
In your controller, you have access to the request
variable (type of ActionDispatch::Request
) which represents the actual request received by your server:
def index
puts request.inspect # see in your server's console the output
# ...
end
With this variable, you can access to the referer
, which returns the path (as String) of the last page seen, or nil
if you came from another domain (or blank page).
To check which page sent your form, you could use:
def my_controller_action
if request.referer.present? && request.referer.include?('/string/to/check/')
# yay!
else
# well, the request is not coming from there
end
end
You could also set it as a before_filter
in your controller in order to check "quietly" the requests and not in each controller's action.