Upgrade Problems
Ancez opened this issue · comments
Hi,
I've encountered several issues with the new updates done to this gem. Could someone explain to me how the new routes are generated? I.e. masquerade_path
& the back route. Also, why are these routes now not showing within the rails routes
command?
I'm working on an app which uses InertiaJs and now, I have to pass the masquerade_path via the serializer instead of relying on the Inertia $routes.account_masquerade_path
.
controllers/devise/masquerades_controller.rb:20
- redirect_to(new_user_session_path) and return
+ redirect_to(send("new_#{masqueraded_resource_name}_session_path")) and return
@Ancez Hi.
Did you make the upgrade of the gem from what version?
for my test app inside of the gem spec/dummy
rails routes | grep masquerade
user_masquerade_index GET /users/masquerade(.:format) users/masquerades#show
back_user_masquerade_index GET /users/masquerade/back(.:format) users/masquerades#back
admin_user_masquerade_index GET /admin_users/masquerade(.:format) devise/masquerades#show
back_admin_user_masquerade_index GET /admin_users/masquerade/back(.:format) devise/masquerades#back
student_masquerade_index GET /students/masquerade(.:format) devise/masquerades#show
back_student_masquerade_index GET /students/masquerade/back(.:format) devise/masquerades#back
Hi @oivoodoo, thank you for your rapid response. I appreciate it
I'm upgrading from version 1.2.0 to 1.3.1. I've cloned the gem itself to play with the dummy. The dummy works as expected. But regardless of the dummy working; the masquerade#show
route from rails routes
is incorrect right? Surely it shouldn't be _index
, and should include the masquerade :id
. To me, it isn't following the Rails standard CRUD routes.
This user_masquerade_index_path
is wrong as it doesn't allow the user to be passed to it. Following from the dummy's example, using masquerade_path(user)
works, but I don't understand where it's defined, how it's defined and why it is not showing in rails routes
- should it be shown there?
Also, the code snipped provided in the Issue description, fixes the devise session so it would be good to get this sorted so this new version actually works for others. This is the main blocking issue preventing me from upgrading this gem.
Hi @Ancez
It's not exactly the show path in this case. URL generated has no id of the user. it's having the encoded value to be used for masquerade.
/users/masquerade?masquerade=BAh7CEkiCGdpZAY6BkVUSSIlZ2lkOi8vZHVtbXkvVXNlci8yP2V4cGlyZXNfaW49NjAGOwBUSSIMcHVycG9zZQY7AFRJIg9tYXNxdWVyYWRlBjsAVEkiD2V4cGlyZXNfYXQGOwBUSSIdMjAyMi0wNC0wMVQwNzozODoxOC4zNTJaBjsAVA%3D%3D--6fd952c0e95b21813435edb2c0172eff750467bf&masqueraded_resource_class=User
it's the example of URL. I can rename show route to the other name. Also it is not the CRUD here.
GET /masquerade + query params -> it's making the sign in. it is not the reading operation.
Also, I don't understand the issue mentioned here above.
Could you share more details about the problem and this change that you mentioned?
redirect_to(send("new_#{masqueraded_resource_name}_session_path")) and return
if you mean these changes:
I believe it would use the right URL once if you don't have the resource to sign in, it will redirect back to the new sign in route.
@oivoodoo
I got the same problem after gem upgrades:
- gem
rails
from 5.2.5 to 6.1.4.6 - gem
devise
from 4.6.2 to 4.8.1 - gem
devise_masqurade
from 0.6.5 to 1.3.11
before upgrade I had:
user_masquerade GET /users/masquerade/:id(.:format) masquerades#show
back_user_masquerade_index GET /users/masquerade/back(.:format) masquerades#back
after upgrade I have:
user_masquerade_index GET /users/masquerade(.:format) masquerades#show
back_user_masquerade_index GET /users/masquerade/back(.:format) masquerades#back
in routes.rb
I have
devise_for :users, controllers: {
masquerades: 'masquerades',
}
So it leads to following result
irb(main):003:0> Rails.application.routes.url_helpers.user_masquerade_path(User.first)
NoMethodError (undefined method `user_masquerade_path' for #<Module:0x00007fd417afd4b0>)
Did you mean? user_masquerade_index_path
irb(main):004:0> Rails.application.routes.url_helpers.user_masquerade_index_path(User.first)
=> "/users/masquerade.1"
Is it possible to debug difference somehow ? Probably I could help with it?
Solution
Change path
- from
Rails.application.routes.url_helpers.user_masquerade_path(user)
- to
Rails.application.routes.url_helpers.user_masquerade_index_path(id: user.to_param, masquerade: user.masquerade_key)
if you use RailsAdmin or outside of main app
After this do not forget to enable caching to avoid strange behaviours with helper methods
# config/environments/development.rb
config.action_controller.perform_caching = true
cc @Ancez