I have following code. Damn, I stuck with this, I know that is very easy...
def create
@question = Question.create(:text => params[:question][:text], :security_token => "test"))
if success = @question.save
respondents = Respondent.find(:all)
respondents.each do |res|
Inquiry.create(:question_id=>res.question.id.to_i, :respondent_id=>res.id.to_i)
end
end
render :json => @question.to_ext_json(:success => success)
end
As you see, I have 3 tables => questions (id, text, security_token), respondents (id, email) and relation-table called inquiry (id, questiond_id, respondent_id). Before I start i told that I have 3 record in my email table. I want do following: When I add question, it also watching how many email i have in my tables (now i have 3 as i said) and add info in inqury table. for example: I NEED FOLLOWING IN MY INQUIRY TABLE (after I have added question):
id | questiond_id | respondent_id
1 | 2 | 1
2 | 2 | 2
3 | 2 | 3
How i can do it? I using each do and check how many email i have, but NOW its doesnt work, dont know why, what i did wrong there in my code?