find active logged in users within the last X minutes
I'm trying to find a way to track what users have been active on my site in the last 15 minutes. I add the update_last_active_status
function to certain actions a user can perform. The last_active_at
column is updated in the User
model with the current time but how can I determine which users have a value in the last_active_at
column that is less than 15 minutes from the current time?
# updates last_active_at column when a user performs certain actions on the site.
def update_last_active_status(user)
user.update_columns(last_active_at: Time.now)
end
How do I find a user that has a login time less than 15 minutes ago? The below does not seem to be working.
# finds if a user has been active in the last 15 minutes
def is_user_active?(user)
if (Time.now - 15.minutes.ago) < (user.last_active_at.to_f)
true
else
false
end
end
ruby-on-rails ruby-on-rails-5
add a comment |
I'm trying to find a way to track what users have been active on my site in the last 15 minutes. I add the update_last_active_status
function to certain actions a user can perform. The last_active_at
column is updated in the User
model with the current time but how can I determine which users have a value in the last_active_at
column that is less than 15 minutes from the current time?
# updates last_active_at column when a user performs certain actions on the site.
def update_last_active_status(user)
user.update_columns(last_active_at: Time.now)
end
How do I find a user that has a login time less than 15 minutes ago? The below does not seem to be working.
# finds if a user has been active in the last 15 minutes
def is_user_active?(user)
if (Time.now - 15.minutes.ago) < (user.last_active_at.to_f)
true
else
false
end
end
ruby-on-rails ruby-on-rails-5
add a comment |
I'm trying to find a way to track what users have been active on my site in the last 15 minutes. I add the update_last_active_status
function to certain actions a user can perform. The last_active_at
column is updated in the User
model with the current time but how can I determine which users have a value in the last_active_at
column that is less than 15 minutes from the current time?
# updates last_active_at column when a user performs certain actions on the site.
def update_last_active_status(user)
user.update_columns(last_active_at: Time.now)
end
How do I find a user that has a login time less than 15 minutes ago? The below does not seem to be working.
# finds if a user has been active in the last 15 minutes
def is_user_active?(user)
if (Time.now - 15.minutes.ago) < (user.last_active_at.to_f)
true
else
false
end
end
ruby-on-rails ruby-on-rails-5
I'm trying to find a way to track what users have been active on my site in the last 15 minutes. I add the update_last_active_status
function to certain actions a user can perform. The last_active_at
column is updated in the User
model with the current time but how can I determine which users have a value in the last_active_at
column that is less than 15 minutes from the current time?
# updates last_active_at column when a user performs certain actions on the site.
def update_last_active_status(user)
user.update_columns(last_active_at: Time.now)
end
How do I find a user that has a login time less than 15 minutes ago? The below does not seem to be working.
# finds if a user has been active in the last 15 minutes
def is_user_active?(user)
if (Time.now - 15.minutes.ago) < (user.last_active_at.to_f)
true
else
false
end
end
ruby-on-rails ruby-on-rails-5
ruby-on-rails ruby-on-rails-5
asked Dec 29 '18 at 19:04
random_user_0891random_user_0891
5511316
5511316
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
def is_user_active?(user)
if user.last_active_at < 15.minutes.ago
true
else
false
end
end
4
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972551%2ffind-active-logged-in-users-within-the-last-x-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
def is_user_active?(user)
if user.last_active_at < 15.minutes.ago
true
else
false
end
end
4
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
add a comment |
def is_user_active?(user)
if user.last_active_at < 15.minutes.ago
true
else
false
end
end
4
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
add a comment |
def is_user_active?(user)
if user.last_active_at < 15.minutes.ago
true
else
false
end
end
def is_user_active?(user)
if user.last_active_at < 15.minutes.ago
true
else
false
end
end
answered Dec 30 '18 at 20:24
Nour OssamaNour Ossama
11
11
4
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
add a comment |
4
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
4
4
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context.
– Dima Kozhevin
Dec 31 '18 at 0:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972551%2ffind-active-logged-in-users-within-the-last-x-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown