Topic: Help with unknown error

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.

Re: Help with unknown error

In the view you are calling @flash_rate.each. @flash_rate is a model, not an enumerable collection (such as an array) so you shouldn't be calling each on it. You can just remove that line along with the related "end" line from the view. You will also need to call @flash_rate.questions instead of flash.questions.

Railscasts - Free Ruby on Rails Screencasts

Re: Help with unknown error

Ok, thanks.  I am trying to cycle through two different enumerables.  Both @flash_rate.questions and @flash_rate.keys are both enumerable collections.  Is there any way to do this?  With models  or instance variables or anything?

Re: Help with unknown error

Yeah, you can call each on questions:

<% @flash_rate.questions.each do |question| %>
  <h1><%=h question %></h1>
<% end %>

I'm not sure how you want to display the question though. That may or may not work the way you want. You can do the same thing for keys as well.

Railscasts - Free Ruby on Rails Screencasts