Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to map to Users::User? #46

Open
joemasilotti opened this issue Mar 22, 2021 · 3 comments
Open

How to map to Users::User? #46

joemasilotti opened this issue Mar 22, 2021 · 3 comments

Comments

@joemasilotti
Copy link

Our app scopes our user model to Users::User. How can we configure API Guard's routes to work with this? (We are also using Devise.)

This seems to be the only combination of for:, as:, and path: options that doesn't raise an error when starting the server. But when POSTing to /api/users/sign_in I get the following error.

NameError (`@api_guard_Users::User' is not allowed as an instance variable name)

  # API Guard Routes
  scope path: :api do
    api_guard_routes for: "Users::User", as: "users", path: "users", controller: {
      authentication: "users/authentication"
    }
  end

  # Devise / Auth Routes
  devise_for :users, class_name: "Users::User", controllers: {
    sessions: "users/sessions",
    registrations: "users/registrations",
    masquerades: "users/admin/masquerades"
  }

I'm assuming (hoping!) this can be fixed in the route configuration. Any help would be greatly appreciated!

@joemasilotti
Copy link
Author

joemasilotti commented Mar 22, 2021

FWIW, hardcoding the instance variable does work.

---
 lib/api_guard/resource_mapper.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/api_guard/resource_mapper.rb b/lib/api_guard/resource_mapper.rb
index ad4ed04..b320b45 100644
--- a/lib/api_guard/resource_mapper.rb
+++ b/lib/api_guard/resource_mapper.rb
@@ -7,7 +7,7 @@ class ResourceMapper
     def initialize(routes_for, class_name)
       @resource_name = routes_for.singularize
       @resource_class = class_name.constantize
-      @resource_instance_name = "@api_guard_#{routes_for}"
+      @resource_instance_name = "@api_guard_user"
     end
   end

jeanpaulsio@358a34f#diff-d35c3a8e79baffe631963359f9cca892b4ed3dc713a84f7e13c019b7ee1291f6R10

@Gokul595
Copy link
Owner

@joemasilotti Thanks for reporting. We need an option to specify the class name in the route configuration as available in devise to support class with namespace. I will work on this.

@joemasilotti
Copy link
Author

Amazing, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants