Jump to content


undefined local variable or method `arr_data'


  • Please log in to reply
1 reply to this topic

#1 mole1066

mole1066

    Forum Newbie

  • Members
  • 5 posts

Posted 25 February 2009 - 05:40 AM

Thanks for this I now have the demo working correctly. I do have one issue though. When I tried to create my own controller and view (including builder) I get the following error



I have copied the helper into lib, edited application helper to reference them, and copied the javascript files. I haven’t used builders before so I can’t see why the variable Is not being passed correctly.



My code is also shown below, do you have any advice?



**************

Error message


undefined local variable or method `arr_data' for #<ActionView::Base:0x217ddcc>



Extracted source (around line #8):



5: #itself an array with first element as label and second element as value

6: xml = Builder::XmlMarkup.new

7: xml.chart(:caption=>'Sales by Product', :numberPrefix=>'$', :formatNumberScale=>'0') do

8:     for item in arr_data

9:         xml.set(:label=>item[0], :value=>item[1])

10:     end

11: end




****************



Dashboard Controller


  def project

    headers["content-type"]="text/html"

    @arr_data = []

    @arr_data << ['Product A','567500']

    @arr_data << ['Product B','815300']

    @arr_data << ['Product C','556800']

    @arr_data << ['Product D','734500']

    @arr_data << ['Product E','676800']

    @arr_data << ['Product F','648500']

  end


View


# The xml is obtained as a string from builder template.

str_xml = render :file=>"dashboard/project", :locals=>{:arr_data => @arr_data}



#Create the chart - Column 3D Chart with data contained in str_xml

render_chart '/FusionCharts/Column3D.swf', '', str_xml, 'productSales', 600, 300, false, false do-%>

<% end -%>




Any help would be most grateful
Michael

#2 srividya_sharma

srividya_sharma

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 943 posts

Posted 27 February 2009 - 07:38 PM

The file names and paths might be causing the problem. This error will occur only if the variable is not being passed via locals hash.
 
But here are a few things to check:
 
1. Please ensure that the view .html.erb file has same name as controller action name. In this case "project". Only then @arr_data is visible to it. The name of the view should be project.html.erb in your case
2. Now, in the view, the builder is rendered using render :file=>'dashboard/project' this means that the project.builder file should be in the dashboard folder inside app/views.
3. Next, you cannot have project.html.erb and project.builder in the same folder because you are referencing one from the other (as seen in #2)

Hope this helps.

regards,
Srividya Sharma