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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With