I currently have a login popup in my header bar which is on every page in my website. I want to be able to reload the current page that the person is on after a successful
Archonic's answer above worked for me. However, in Rails 3, I had to place this in a respond_to
block in order to avoid an 'ArgumentError (too few arguments)' error:
respond_to do |format|
format.js {render inline: "location.reload();" }
end
Building on Archonic's and Elena's Answers, the reload function accepts a parameter to force the page to reload from the server aka forceGet, instead of from cache. A parameter can be set by the controller logic, like successful or failed login of a user, to trigger the desired behavior when it is sent to the page.
# force_get = controller_logic ? true : false
respond_to do |format|
format.js { render inline: "location.reload(#{force_get});" }
end
UPDATE: the logic has been deprecated for the forceGet option. If you do want to reload from the server you can use this logic:
# force_get = controller_logic ? true : false
respond_to do |format|
format.js { render inline: force_get ? "window.location.href = window.location.href;" : "location.reload();" }
end
just redirect to whatever url you want in the function:
redirect_to what_ever_path