What does resource mean in Devise?
Asked Answered
C

2

8

I want to change what happenes in devise when a user logs in.. When I look at the source code the word resource is everywhere, but I can't understand what it is a stand in for. Does it only pertain to devise and warden?

def after_sign_in_path_for(resource)
  stored_location_for(resource) ||
    if resource.is_a?(User) && resource.can_publish?
      publisher_url
    else
      super
    end
end
Crockery answered 27/11, 2016 at 4:49 Comment(1)
Possible duplicate of Combining Devise with resources :users in RailsImponderable
A
10

Resource is an abstraction name of instance of a user. It can be configured in devise settings to work with Admin model or any other.

By default it's the first devise role declared in your routes

devise :users  # resource is instance of User class
devise :admins # resource is instance of Admin class
Anonym answered 27/11, 2016 at 4:56 Comment(2)
I'm still confused. I'm using devise with the user model. Does that mean "resource" a stand in for user?Crockery
Yes. By default it's the first devise role declared in your routes. devise_for :usersAnonym
R
3

Alex's answer says it succintly, but it may not be clear to everyone, given the comment above:

"Resource" is how developers want to refer to their "User" Model

The authors of devise realise that those who use the gem will want it customised differently. Some people will want to call their users: Users, others will want to call them: Swimmers, or Golfers, or Presidents, as the case may be. "Resource" is basically a substitute for the name of the users that app developers will utilize in the future. Devise doesn't care what users are actually called: no matter what it is called, to devise, your users will be known as simply "resource". If it had been any other way, then the authors of the gem would have to force app developers to call their users: Administrator, or Admin - which is very restrictive and developers will not like that.

Raila answered 9/2, 2018 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.