Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Here's the code:

    class MulticastController < ApplicationController
@@groups=Array.new
@@groups=[]

@@group_name=Array.new
@@group_name=[]

    def getResults
            @@groups
            @@group_name
    if request.post?

             if params[:creategroup] #makes a new group
                @@groups << searchHash
                @@group_name << params[:groupname]

                if @@groups.size>5
                    @@groups[0].delete
                    @@group_name[0].delete
                end

            end

            if params[:displaygroup] 
                @@group_name.each_with_index do |gr,i|
                if(gr==params[:inputgroupname])
                    @results=Person.where(@@groups[i]).to_a
                    render :new_results, :layout => false
                end
            end
                       end

On the views portion I have-

        <div class="span6 service">
            <legend>Groups</legend>
            <% group_name.each do|grp|%>
                <%= grp %><br>
            <%end %><br><br>
            <input type="hidden" name="displaygroup" value="1">
            <div>
                <input type="text" name="inputgroupname" value="inputgroupname">
            </div>

I dont know what to do, its giving me an " uninitialized class variable @@group_name in ActionView::CompiledTemplates " error.

I want the variables group and group_name to be common to all the instances of multicast. stuck.

share|improve this question
add comment

2 Answers

try

def getResults
        @@groups ||= []
        @@group_name ||= []

instead of

def getResults
        @@groups
        @@group_name

The operator ||= will initialize your variable, but only if it is not already initialized.

And please listen to the comments of Ivan Shamatov about code style and patterns.

share|improve this answer
add comment

Well, to access groups class variables you need to do MulticastController.groups in your view.

You are missing so much about ruby here, not even talking about rails.

  • using spaces instead of tabs
  • using underscore naming instead of camelCase
  • using REST
  • using MVC, where controller just operate with objects but not storing anything in itself

So here are some questions: why are you doing like this?

@@groups=Array.new
@@groups=[]

or like that?

def getResults
  @@groups
  @@group_name

Your code is really hard to understand...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.