3

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.

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.