Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does resource mean in Devise?

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
like image 344
Jeremy Avatar asked Nov 27 '16 04:11

Jeremy


People also ask

What is devise UID?

As Devise support OmniAuth integration by default. In order to do so it creates two extra column provider and uid where provider consist oAuth provider i.e facebook, google, linkedin etc. and uid will consist unique id of the user who logged in using oAuth.

What is devise in Ruby?

Devise is the cornerstone gem for Ruby on Rails authentication. With Devise, creating a User that can log in and out of your application is so simple because Devise takes care of all the controllers necessary for user creation ( users_controller ) and for user sessions ( users_sessions_controller ).

What is devise install?

Now that you have set everything up you can create your first user. Devise creates all the code and routes required to create accounts, log in, log out, etc. Make sure your rails server is running, open http://localhost:3000/users/sign_up and create your user account.


2 Answers

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
like image 141
Alex Kojin Avatar answered Oct 01 '22 08:10

Alex Kojin


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.

like image 45
BenKoshy Avatar answered Oct 01 '22 08:10

BenKoshy