Obelix
2007-Oct-04 01:12 UTC
Weird active record problem - goes away with cache_classes change
I have three active record objects, User, Question and Answer
- Questions belong to a user and has_many answers
- Answer belongs to a user
Now, when I start with an array of answers, I can do this
successfully:
for a in answers
a.user.user_id
end
If I do this:
for q in questions
answers = q.answers
for a in answers
a.user.user_id
end
end
It works the first time, but it fails the 2nd time on with this:
ActionView::TemplateError (undefined method `user'' for #<Answer:
0x351617c>) on line #45 of app/views/lib/_qnalist.rhtml:
42: <div class="qna-a-
details">
43: <span
class="qna-a-body"><%= format_line_wrap(a.body, width, 14)
%></
span><br>
44: <span
class="qna-a-info">
45:
Answered by <%= a.user.user_id %> - <%= a.created_at %>
46: </span>
47: </div>
48: <div class="very-
narrow-space"> </div>
However, this is fixed IF I change development.rb and change
cache_classes to true
config.cache_classes = true
I have no clue what is happening :(.
Any one knows how to fix this?
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- config.cache_classes true or false in test environment?
- edge rails config.cache_classes = true breaks applications
- Setting cache_classes to false results in blank pages
- config.cache_classes value ignored in development mode under Apache 2
- Windows, Segmentation Faults, config.load_paths and config.cache_classes
