Forum: Ruby on Rails static variables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sijo k. (Guest)
on 2009-04-25 08:49
Hi
  In controller I have
 def role_wise_summary_graph_render
    @graph1 = open_flash_chart_object(300,200,
"#{summary_graph_path(:role_name => 'Role1')}", true)
    @graph2 = open_flash_chart_object(300,200,
"#{summary_graph_path(:role_name => 'Role2')}", true)
  respond_to do |format|
  --------------
        end
  end

###summary_graph_path  => :action => draw_role_level_summary_graph
def draw_role_level_summary_graph

@role1_array,@role2_array,@open_requests =
MyRequest.get_role_wise_summary_graph_data

    if params[:role_name] == 'Role1'
      role_data_array = @role1_array
    elsif params[:role_name] == 'Role2'
      role_data_array = @role2_array
    end
     graph =
role_level_graph(params[:role_name],role_data_array,@open_requests)
      render :text => graph.render
  end

    Here in above role_level_graph is a library function finally
responsible for drawing graph  The above code is working
   My question is in the above how can I make the varibales
@role1_array,@role2_array,@open_requests static so that only once
MyRequest.get_role_wise_summary_graph_data get called Because I need it
only once But happens now is all the two times this def gets called How
can I avoid this to call this only once and get the details

Thanks in advance
SSijo
This topic is locked and can not be replied to.