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 login. How do I do this in the controller?
def create #declaring and defining user variable stuff if user.save #reload current page <--how do I do this? end end
Thanks
Reloads the attributes of object(here @user) from the database. It always ensures object has latest data that is currently stored in database.
The first() is an inbuilt method in Ruby returns an array of first X elements. If X is not mentioned, it returns the first element only. Syntax: range1.first(X) Parameters: The function accepts X which is the number of elements from the beginning. Return Value: It returns an array of first X elements.
CanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single location (the Ability class) and not duplicated across controllers, views, and database queries.
For my application, I use redirect_to :back
and it does the trick. However, I doubt this might have an error in a non general use case(s) (user came from a special page?) but i haven't found it so far in my app.
If you're looking for a way to get the page to refresh (typically redirect_to :back
) with an XHR request, you don't have to look for a way to change the response type - just tell the page to reload with inline JS.
format.js {render inline: "location.reload();" }
Like Elena mentions, this should go in a respond_to block, like so:
respond_to do |format| format.js {render inline: "location.reload();" } end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With