I'm trying to add a simple feature to locomotivecms (github). A very simple feature: currently users are redirected to the "main admin hub" (/admin/) after logging in - even if they were trying to edit a different page. I want them to be directed to that page after logging in instead.
It seems a very simple and reasonable thing to add, but after two days trying I've decided to ask for help.
This is what I've found out so far.
/admin/
route. For example, the login path is /admin/log_in
. Most controllers are inside an /admin/
subfolder, too./admin/sessions_controller
that apparently "fixes" the url to be visited after being logged in to the /admin/
root.Here's the relevant bit:
def after_sign_in_path_for(resource)
admin_pages_url
end
I'm nearly sure that what I need is this instead:
def after_sign_in_path_for(resource)
stored_location_for(resource) || admin_pages_url
end
If I have understood Devise's documentation correctly, stored_location_for
searches for a value in the session (session['admin_return_to']
in Locomotive's case) to "see if someone wants to go back somewhere". If it's empty, the || ensures a safe path to the admin root.
Unfortunately this doesn't work. It seems that the session variable that I need is never set up. I was assuming that Devise did this kindof automatically.
Must I set the session value myself? If so, where? Or are my assumptions wrong?
Thanks a lot!
Best solution is updating to the latest version of LocomotiveCMS.