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

  • SEARCH
  • Home
  • 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 8237941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:38:33+00:00 2026-06-07T19:38:33+00:00

First off, I’m following the practice found here for Rails concerns (great idea!): https://gist.github.com/1014971

  • 0

First off, I’m following the practice found here for Rails concerns (great idea!): https://gist.github.com/1014971

I’m getting an error though:

undefined method `search' for #<Class:0x5c25ea0>
app/controllers/accessories_controller.rb:6:in `index'

I DO have my /app/models/concerns/ directory loaded in /config/application.rb. So the “concern” modules ARE being loaded. Just wanted to point that out.

Here is my code:

/app/models/concerns/searchable.rb

module Searchable
  extend ActiveSupport::Concern

  # Add a "search" scope to the models
  def self.search (search)
    if search
      where('name LIKE ?', "%#{search}%")
    else
      scoped
    end
  end
end

/app/models/accessory.rb

class Accessory < ActiveRecord::Base
  include Searchable

  ...
end

/app/controllers/accessories_controller.rb

class AccessoriesController < ApplicationController

  def index
    @accessories  = Accessory.search(params[:search])

    ...
  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-07T19:38:34+00:00Added an answer on June 7, 2026 at 7:38 pm

    Well, with a little more toying around I figured out what is wrong!

    When you’re wanting to directly modify the Model from within the Module (concern), you need to wrap the functionality inside an included block.

    I’ve changed my concern module to the following:

        module Searchable
            extend ActiveSupport::Concern
    
            included do
                # Add a "search" scope to the models
                def self.search (search)
                    if search
                        where('name LIKE ?', "%#{search}%")
                    else
                        scoped
                    end
                end
            end
    
        end
    

    That is it! Hopefully this will help someone else with the same quesion!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first off I'm a noob to PHP but here is my problem. I am
First off, I'm using XCode 4.0.2. Okay, here is my issue. I can build
First off I'm horrible with regex, hoping I can get some help here cause
First off, here's my code: Sub SimulatePortfolio() Dim lambda As Double Dim num As
First off, this is the error I am getting java.lang.OutOfMemoryError at coderaustin.com.FileEncryptor.encryptFile(FileEncryptor.java:56) at coderaustin.com.Main.onCreate(Main.java:41)
First off...here's the problem... Give an example of a directed graph G = (V,
first off a short explanation... the following two lines assure that once my website
First off, according to http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx , the List.Find method is only listed as throwing
First off, I'm coming (back) to Java from C#, so apologies if my terminology
First off, I would like to make clear, that I am SUPER NEW TO

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.