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 8794799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:02+00:00 2026-06-13T23:18:02+00:00

In my controller I have an instant variable with a where method, its part

  • 0

In my controller I have an instant variable with a where method, its part of a filter in the Search Controller.

@items = @items.where([ 'borrowable = ?', true]) if params[:top_filter] == 'borrow'

The borrowable = ?, true bit is completely wrong. What I want is to filter the @items that are borrowable by using a method in the Item's model called borrowable?.

How do I do this?

The method in the Item model is below.

    def borrowable?(current_user, user, item, controller)
      false
      if user.invited?(current_user, user)
        item.pieces.each do |piece|
          if piece.available?(current_user, piece)
            true
          end
        end
        if controller == "pages"
          true
        end
      end
    end
  • 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-06-13T23:18:03+00:00Added an answer on June 13, 2026 at 11:18 pm

    If it’s relying on model level code, then you won’t be able to put it in a where clause. The where clause is trying to grab a list of items, but on each item you want to call a method, but you don’t have the method until your grab the items. You could potentially use a stored procedure on the DB, but just in Rails code you could do this:

    @items = @items.keep_if { |item| item.borrowable? } if params[:top_filter] == 'borrow'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have controller and model. i am modifying a variable value in a model,
Does Spring's Controller have any sort of destroy/cleanup method? I couldn't find anything in
I have Controller A and controller B is pushed on top of it in
I have controller users . In this controller I have action account which is
Have Controller: public class MyController : Controller { [HttpGet] public ActionResult MyAction(int iMode, string
I have controller with action new , and I want it to create ActiveRecord::Base
I have controller PlayerController and actions inside: View , Info , List . So
I have Controller: [MySite]\Controllers\DistributionTools\TrackingChannelsController.cs [HttpPost] public void InitTcFirstPageView() { var model = new TcFirstPageModel
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
Inside my Controller i have function that runs after user clicks on item, which

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.