ruby on rails - Problem with activerecord find -


i have 5 tables , related between. everythings good, perfectly! tried make script, if in inquiry table field is_answered = 0, find respondents (by respondent_id in question table) , send them letter have mistake!

i have code:

inquiry       = inquiry.find(:all, :conditions => ["is_answered = 0"]) question      = inquiry.question  respondents   = respondent.find(:all, :conditions => ["id = (?)", question.user_id])  respondents.each |r|   notifier.deliver_user_notification(inquiry) end 

and when typing ruby blah.rb error:

undefined method `question' #<array:0x7f646c82b568> 

what mistake?

ps - inquiry table (id, question_id, respondent_id) relationship table between questions , answers. pss - respondent table related inquiry.

the problem have more inquiry following returns array.

inquiry.find(:all, :conditions => ["is_answered = 0"]) 

try following, mindful of how many sql queries does, there optimisations can made:

inquiry       = inquiry.find(:all, :conditions => ["is_answered = 0"]) inquiry.each |i|     question      = i.question     respondents   = respondent.find(:all, :conditions => ["id = (?)", question.user_id])      respondents.each |r|       notifier.deliver_user_notification(inquiry)     end end 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -