Lately I was looking to evaluate the parameters from an post action.
The background is my questions model with four answers and one column with the a pointer to the right answer. My index.html view looks like this:
After I have checked some boxes a post action is done and per se the create method is called in the corresponding controller:
The controller just puts the parameter on the screen as a flash message when the view is reloaded. NOTE: I put an extra flash message code in my view above.
Now I just have to evaluate it:
The background is my questions model with four answers and one column with the a pointer to the right answer. My index.html view looks like this:
<%= form_tag do %>
<table>
<% @questions.each do |question| %>
<tr>
<td>
<%= question.content -%>
</td>
<td>
<%= question.answer1-%>
<%= check_box_tag 'question_ids[]', question.id.to_s + '_1' -%>
</td>
<td>
<%= question.answer2-%>
<%= check_box_tag 'question_ids[]', question.id.to_s + '_2' -%>
</td>
<td>
<%= question.answer3-%>
<%= check_box_tag 'question_ids[]', question.id.to_s + '_3' -%>
</td>
<td>
<%= question.answer4-%>
<%= check_box_tag 'question_ids[]', question.id.to_s + '_4' -%>
</td>
</tr>
<% end %>
</table>
<%= flash[:message] %><br>
<%= submit_tag("Post") %>
<% end %>
After I have checked some boxes a post action is done and per se the create method is called in the corresponding controller:
# POST /diagnoses
# POST /diagnoses.json
def create
flash[:message] = params[:question_ids]
respond_to do |format|
format.html { redirect_to diagnoses_url }
format.json { head :no_content }
end
end
The controller just puts the parameter on the screen as a flash message when the view is reloaded. NOTE: I put an extra flash message code in my view above.
Now I just have to evaluate it:
- split id and answer number
- compare answer number with column in model of given id
Kommentare
Kommentar veröffentlichen