I have a nested form for survey responses, but the form data is not
being posted to the table; I get no errors, just null values for the
data from params (''question_id'', ''answer_id''
and ''note)''.
Please help!!! And thanks in advance !!
------------------------------------------------------------------------------------------------------------
Model:
class CreateResponses < ActiveRecord::Migration
def self.up
create_table :responses do |t|
t.integer :request_id
t.integer :question_id
t.integer :answer_id
t.text :note
t.timestamps
end
end
-----------------------------------------------------------------------------------------------------------------
Controller:
def survey_response
@request = Request.find(params[:id])
@survey = Survey.find(:first, :conditions => id @request.survey_id)
@question = Question.find(:all, :conditions => survey_id @survey.id)
@resultSet = Array.new
@question.each do |question|
answers = Answer.find(:all, :conditions => ["question_id = ?",
question.id])
questionAnswerPair = [question, answers]
@resultSet << questionAnswerPair
questionAnswerPair=[]
answers=[]
end
if request.post?
@response = Response.new(:request_id => @request.id,
:question_id => (params[:question_id]),
:answer_id => (params[:answer_id]),
:survey_id => @survey.id,
:note => (params[:note])
)
end
end
----------------------------------------------------------------------------------------------------------------------
survey_response View:
<tr>
<% @resultSet.each do |questionAnswerPair| %>
<tr class="<%= cycle(''odd'',
''even'') %>">
<td><%= questionAnswerPair[0].content
%></td><br>
<td><%= select("@response", "answer_id",
questionAnswerPair[1].collect {|answer| [answer.content,
answer.id]}, :include_blank => true) %></td><p>
</tr>
<% end %>
</tr>
<p>
Additional Comments:<br>
<%= f.text_area :note, :size => "60x5" %>
<p>
<%= f.submit "Submit" %></p>
<% end %>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.