Topic: Working Development code breaks in Production mode

Hi, this is my first post here.  NielsenE is a friend who's been helping me with my Rails learning, and he's pointed me to this forum as an excellent resource.

I'm working on an application that will allow people to enter research questions and tag them with keywords.  I'm developing on my home machine (OS X 10.4.7), then checking in code via subversion and checking code back out to our shared server at Dreamhost.  For over a month, things have been working fine.  I've switched to production mode on Dreamhost (I'm in development mode on my home machine), made code changes, uploaded them and then updated the server, rebooted the rails processes, and things worked fine.  Until last night.

I made some more changes, and they were all working fine on my machine.  But after I went through getting them into the server, one set of pages stopped working.  The relevant part of the production.log file suggests that it doesn't like a specific method:

ActionView::TemplateError (undefined method `question' for #<Array:0x40a3abb0>) on line #25 of app/views/questions/list.rhtml:
22:                             <ul>
23:                             <% subquestions = Question.find_all_subquestions(question) %>
24:                             <% for underq in subquestions do -%>
25:                                     <%= "<li><b>" + underq.question + "</b></li>" %>
26:                             <% end -%></ul>
27:                             </div>
28:                     <% end %>

    #{RAILS_ROOT}/app/views/questions/list.rhtml:25:in `_run_rhtml_questions_list'
    #{RAILS_ROOT}/app/views/questions/list.rhtml:24:in `each'


But there are a couple of weird parts.  First, not only does it work on my machine, but it works on the production server if I switch it to development mode!  Second, if I put in the line:
<%= h underq.inspect -%>

right before line 25, it displays a Question object like this:
 #<Question:0x2258390 @attributes={"updated_at"=>"2006-08-24 23:04:41", 
"regime_id"=>"6", "id"=>"24", "approvedYesNo"=>nil, "question"=>"What was I going to ask?",
"owner_id"=>nil, "user_id"=>"1", "context"=>"Blah blah more testing. This should be long
enough for now.", "action_id"=>nil, "difficulty"=>nil, "importance"=>nil, "position"=>"1",
"pillar_id"=>"2", "parent_id"=>"23", "created_at"=>"2006-08-24 23:04:41",
"milestone_id"=>nil}, @children=[]>

Even if there are multiple sub-questions, it lists them each like that.  So I don't know why it's saying that the undefined method is for an Array ( <Array:0x40a3abb0>) instead of a Question.  I suspect that's the heart of the issue, but we (NielsenE and I) can't figure out why it refers to it as an Array.

Does anybody have any ideas as to why this weird problem only shows up in the production mode, and not development mode?  Why does Rails seem to think it's dealing with an Array object instead of a Question object when every other indicator is that it sees things properly?

Re: Working Development code breaks in Production mode

Well, the problem is now fixed.  I'm not 100% sure, but I think the problem was the 'do' at the end of the 'for' line.  If that was the problem, I don't know why it worked OK on my home system (both in development and production modes) and the server (in development mode), but it's working now.  I'll report if the problem pops up again.

Re: Working Development code breaks in Production mode

I'm still a newbie in Rails, but isn't the "for" syntax either

for x in y
   blah blah
end

or

for x in y do |var|
   blah blah
end

?

That way, the lack of the var could be what was causing your problems.

Although then I don't understand why would it work OK on your dev machine

Re: Working Development code breaks in Production mode

When using for, the do is unecessary.  The alternate is..

list.each do |item|
  puts item
end

I imagine that the for command is just an alias for each.