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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:19:25+00:00 2026-05-24T10:19:25+00:00

I am a beginner in Rails and i have a problem with scope. I

  • 0

I am a beginner in Rails and i have a problem with scope.

I have my class with 2 scopes :

class Event < ActiveRecord::Base
  belongs_to :continent
  belongs_to :event_type 

   scope :continent, lambda { |continent|
     return if continent.blank?
     composed_scope = self.scoped
     composed_scope = composed_scope.where('continent_id IN ( ? )', continent).all
     return composed_scope
   }

   scope :event_type, lambda { |eventType|
     return if eventType.blank?
     composed_scope = self.scoped
     composed_scope = composed_scope.where('event_type_id IN ( ? )', eventType).all
     return composed_scope
   }

end

And in my controller i want to use this 2 scopes at the same time. I did :

def filter
  @event = Event.scoped
  @event = @event.continent(params[:continents]) unless params[:continents].blank?
  @event = @event.event_type(params[:event_type]) unless params[:event_type].blank?

  respond_with(@event)
end

But i doesn’t work, I have this error :

 undefined method `event_type' for #<Array:0x7f11248cca80>

It’s because the first scope return an array.

How can I do to make it work?

Thank you !

  • 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-24T10:19:26+00:00Added an answer on May 24, 2026 at 10:19 am

    You should not append ‘.all’ in your scopes:

    It transforms a chainable ActiveRelation into an Array, by triggering the SQL query.

    So simply remove it.

    Bonus:

    Some refactoring:

    scope :continent, lambda { |continent|   
      self.scoped.where('continent_id IN ( ? )', continent) unless continent.blank?
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models class Project < ActiveRecord::Base has_many :project_members has_many :members, :through
Hi im quite beginner in rails. i have a problem suggestion will be appreciated.
I have the model Post: class Post < ActiveRecord::Base has_one :location, :dependent => :destroy
I am a beginner at Ruby on Rails. Currently, I have the following problem:
I am a beginner with Ruby on Rails. I have a question regarding organizing
I am a beginner in using Rails and Git I have InstantRails installed and
I am a beginner Ruby on Rails developer. So far I have created several
Complete beginner to Rails here: In Rails: I have a Model Post, which hasmany
Beginner rails/javascript question: Let's say that I have a simple Circle model in a
I'm a RoR beginner, and I have a problem with my app. I have

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.