Hello everyone, Im using a charting plugin called openflashcharts and I seem to be getting an error when trying to use respond to. Now I know hashes are supposed to have an even amount of elements in them, but I dont see where I am going wrong. Heres my code: def index workouts = Workout.find_all_by_user_id(current_user.id) spinclasses = SpinClass.find_all_by_user_id(current_user.id) workouts_array = Array.new spinclasses_array = Array.new workouts.each do |w| workouts_array << [w.created_at.to_date, w.calories_burned] end spinclasses.each do |sc| spinclasses_array << [sc.created_at.to_date, sc.calories_burned] end title = Title.new("Calories burned.") respond_to do |wants| wants.html { @graph = open_flash_chart_object(600, 300, url_for(:action => ''index'', :format => :json)) } wants.json { line = Line.new() line.text = "Line" line.width = 1 line.colour = ''#5E4725'' line.dot_size = 5 line.values = workouts_array chart = OpenFlashChart.new(title) chart.add_element(line) render :text => chart, :layout => false } end end and heres my error: /Users/Zack/Desktop/General/Rails/ergotech/app/controllers/charts_controller.rb:25: odd number list for Hash /Users/Zack/Desktop/General/Rails/ergotech/app/controllers/charts_controller.rb:30: odd number list for Hash /Users/Zack/Desktop/General/Rails/ergotech/app/controllers/charts_controller.rb:31: syntax error, unexpected tIDENTIFIER, expecting ''}'' line.text = "Line" ^ /Users/Zack/Desktop/General/Rails/ergotech/app/controllers/charts_controller.rb:40: syntax error, unexpected ''}'', expecting kEND /Users/Zack/Desktop/General/Rails/ergotech/app/controllers/charts_controller.rb:54: syntax error, unexpected $end, expecting kEND Many thanks, zack. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Zack Nathan
2010-Oct-11 11:49 UTC
Re: odd number list for Hash error when using respond_to
bump.. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Erol Fornoles
2010-Oct-11 12:29 UTC
Re: odd number list for Hash error when using respond_to
Could you try making your wants.html and wants.json blocks use do...end instead of {...} and see if that works? wants.html do @graph = ... end wants.json do line = Line.new() ... end On Oct 11, 7:49 pm, Zack Nathan <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> bump.. > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Oct-11 15:01 UTC
Re: odd number list for Hash error when using respond_to
On Oct 10, 2:26 pm, Zack Nathan <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> respond_to do |wants| > wants.html > { > @graph = open_flash_chart_object(600, 300, url_for(:action => > ''index'', :format => :json)) > } >Because of the linebreak ruby things you are calling wants.html with no block or arguments and thinks that the block you have put on the next line is a hash literal Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Zack Nathan
2010-Oct-11 21:19 UTC
Re: odd number list for Hash error when using respond_to
Frederick Cheung wrote in post #947355:> On Oct 10, 2:26 pm, Zack Nathan <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> respond_to do |wants| >> wants.html >> { >> @graph = open_flash_chart_object(600, 300, url_for(:action => >> ''index'', :format => :json)) >> } >> > Because of the linebreak ruby things you are calling wants.html with > no block or arguments and thinks that the block you have put on the > next line is a hash literal > > FredAhh thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.