Search code examples
ruby-on-railsrubydeviseruby-on-rails-5

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

Solution

  • 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