Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:29:42+00:00 2026-05-24T07:29:42+00:00

Currently, in my controller I am assigning values to a variable like so: @tasks

  • 0

Currently, in my controller I am assigning values to a variable like so:

@tasks = @list.tasks.where(:importance => 'high', :active => true).search(params[:search])

What I’m wondering is if there is a way with .where or any other way to use a model method for selection selection. I have a model method that returns a string representing a relative due date:

def due
    if self.due_date < Date.today + 2.days
      return 'now'
    elsif self.due_date < Date.today + 1.week
      return 'soon'
    else
      return 'later'
    end    
end

I don’t want to store this .due value in the database, as it’ll be changing constantly based off what the date is. But what I, in theory, would want to do is something like this in my controller for selection:

@tasks = @list.tasks.where(:importance => 'high', :active => true, :due => 'now).search(params[:search])

But this will not work as .due is not in the database. Should I be doing this with scopes? Anyway, appreciate the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:29:43+00:00Added an answer on May 24, 2026 at 7:29 am

    You could do scopes:

    scope :due_now, lambda { where("due_date < ?", Date.today + 2.days) }
    scope :due_soon, lambda { where("due_date < ?", Date.today + 1.week) }
    scope :due_later, lambda { where("due_date >= ?", Date.today + 1.week) }
    

    Alternatively, you could just use your class method like so:

    @tasks = @list.tasks.where(:importance => 'high', :active => true).select{ |task| task.due == 'now' }.search(params[:search])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a controller were I would like to keep track of logging
I currently have this method in a controller: def show property = Property.find(params[:id]) respond_to
Currently my controller looks like this: public class ProductBrandsController : Controller I've read online
Our application currently looks like this: [ Navigation Controller] [ Content ] [ Tab
Currently my controller lets a user submit muliple links at a time. It collects
I am developing an application that currently has a View Controller (call it ViewControllerX).
Here is the thing. I currently have a tabBar controller, with several navigation controllers
SORRY:: I forgot that params[:user_id] does not exist in the controller, using current_user.id !
I'm currently testing the controller in my mvc app and I'm creating a fake
I currently have a controller method that returns a JsonResult: public JsonResult EditField(int FieldID,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.