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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:08:00+00:00 2026-06-09T01:08:00+00:00

I have an array in my model but I don’t know how to access

  • 0

I have an array in my model but I don’t know how to access it from some defs in this model

private 

topics =
[
'en','Sports','sports',
'en','Sports,Soccer,Football','soccer,football',
]

def self.load   
    topics.each_slice(3).map do |lang,tags,searchterms|
        load_data(lang,tags,searchterms) 
    end 
end

But when I try from to execute from console it shows an error

NameError: undefined local variable or method `topics’ for Class:

I don’t want to declare the array inside def because I need other methods from model can access to this array

Any idea? thanks

  • 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-09T01:08:03+00:00Added an answer on June 9, 2026 at 1:08 am

    Because you’ve defined topics as local variable but trying to get it as class variable.

    Just change it to @@topics both in the definition and in the method load, then it should work.

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

Sidebar

Related Questions

I have some checkboxes bound to an array in my model. This works great,
I have a pretty simple form with some fields from a doctrine model. $this->widgetSchema['fields']
for example: I have created one javascript property array model with some properties like
I have this widget: $this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' => 'MyTable', 'method' => 'myMethod', 'key_method' =>
I have this array property in my model and would like to see it
I have a model that I'm trying to retrieve an array of data from,
Please have a look at this validation array in my cakephp app for model
I have two dropdownlist in one view but i don't know if i can
I have, I believe, a simple problem, but I don't know how to solve
I don't know whether this is question is asked before or not but i

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.