Ok, I have been messing with this for a while and CANNOT figure how I am getting this particular error. Here is what I have. Model class FlashRate < ActiveRecord::Base belongs_to :review has_many :reviews attr_accessor :questions, :keys end Controller def flash_rate @flash_rate = FlashRate.new @review = Review.find(params[:id]) @relation = Relation.find(@review.relation.id) @flash_questions = FlashRate.new @flash_rate = FlashRate.new @flash_rate.questions = @relation.get_questions @flash_rate.keys = [ :prop1, :prop2, :prop3, :prop4, :prop5, :prop6, :prop7 ] end View <% @block_title = "Flash Rate" -%> <% @block_description = "Don''t make others repeat your mistakes" -%> <%= start_form_tag(:action => "save_flash_rate" , :id => @review ) %> <% @flash_rate.each do |flash| %> <div id="idChoice"> <div class="choice"> <h5><%= flash.questions %></h5> <%= select(:flash_rate, flash_keys , @scale ) %> </div> <% end %> <%= submit_tag(" Flash Rate ") %> <%= end_form_tag %> </div> When I run this code I get an error I don''t understand from the Action Controller. It says: undefined method `each'' for #<FlashRate:0x3b22cc0> Any know why I would get this error? Thanks for the help. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I''m not sure what you''re trying to do (It sounds like you''re trying to build a quiz game), but I think the error you are getting related to each has to do with this line in the view: <% @flash_rate.each do |flash| %> Your @flash_rate object doesn''t understand ''each''. I think you need to refer to one of the following in your view instead: @flash_rate.reviews,@flash_rate.questions or @flash_rate.keys That or (I think) you can make flash_rate implement enumerable (by implementing each) - the book "Ruby for Rails" talks about that, as I''m sure the Pickaxe book does also. Hope this helps!!! Dominique> Controller > > def flash_rate > @flash_rate = FlashRate.new > @review = Review.find(params[:id]) > @relation = Relation.find(@review.relation.id) > @flash_questions = FlashRate.new > @flash_rate = FlashRate.new > @flash_rate.questions = @relation.get_questions > @flash_rate.keys = [ :prop1, :prop2, :prop3, :prop4, :prop5, :prop6, > :prop7 ] > > endcfinlayson wrote:> Ok, I have been messing with this for a while and CANNOT figure how I am > getting this particular error. Here is what I have. > > Model > > class FlashRate < ActiveRecord::Base > belongs_to :review > has_many :reviews > attr_accessor :questions, :keys > end > > Controller > > def flash_rate > @flash_rate = FlashRate.new > @review = Review.find(params[:id]) > @relation = Relation.find(@review.relation.id) > @flash_questions = FlashRate.new > @flash_rate = FlashRate.new > @flash_rate.questions = @relation.get_questions > @flash_rate.keys = [ :prop1, :prop2, :prop3, :prop4, :prop5, :prop6, > :prop7 ] > > end > > View > > <% @block_title = "Flash Rate" -%> > <% @block_description = "Don''t make others repeat your mistakes" -%> > > <%= start_form_tag(:action => "save_flash_rate" , :id => @review ) %> > <% @flash_rate.each do |flash| %> > <div id="idChoice"> > <div class="choice"> > <h5><%= flash.questions %></h5> > <%= select(:flash_rate, flash_keys , @scale ) %> > </div> > > <% end %> > <%= submit_tag(" Flash Rate ") %> > <%= end_form_tag %> > </div> > > > When I run this code I get an error I don''t understand from the Action > Controller. It says: > undefined method `each'' for #<FlashRate:0x3b22cc0> > > Any know why I would get this error? > > Thanks for the help.-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
cfinlayson wrote:> Ok, I have been messing with this for a while and CANNOT figure how I am > getting this particular error. Here is what I have. > > Model > > class FlashRate < ActiveRecord::Base > belongs_to :review > has_many :reviews > attr_accessor :questions, :keys > end > > Controller > > def flash_rate > @flash_rate = FlashRate.new > @review = Review.find(params[:id]) > @relation = Relation.find(@review.relation.id) > @flash_questions = FlashRate.new > @flash_rate = FlashRate.new > @flash_rate.questions = @relation.get_questions > @flash_rate.keys = [ :prop1, :prop2, :prop3, :prop4, :prop5, :prop6, > :prop7 ] > > end > > View > > <% @block_title = "Flash Rate" -%> > <% @block_description = "Don''t make others repeat your mistakes" -%> > > <%= start_form_tag(:action => "save_flash_rate" , :id => @review ) %> > <% @flash_rate.each do |flash| %> > <div id="idChoice"> > <div class="choice"> > <h5><%= flash.questions %></h5> > <%= select(:flash_rate, flash_keys , @scale ) %> > </div> > > <% end %> > <%= submit_tag(" Flash Rate ") %> > <%= end_form_tag %> > </div> > > > When I run this code I get an error I don''t understand from the Action > Controller. It says: > undefined method `each'' for #<FlashRate:0x3b22cc0> > > Any know why I would get this error? > > Thanks for the help.I absolutely agree with Dominique. I just finished David Black''s one week ruby bootcamp (he''s the fellow that wrote "Ruby for Rails" and one of the best thing I brought away from the class is a new comfort level with script/console. By using script/console, you can run an irb session that has access to all of the models and controllers in your application. Its use un troubleshooting cannot be stressed enough. You can do things like flash_rate.respond_to? It is an invaluable tool that will save you hours of guessing when trying to troubleshoot a problem, and one I urge you to get comfortable with. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---