Skip to content

Commit 758a586

Browse files
authored
Merge pull request #353 from DigitalCurationCentre/issue_302
radiobuttons question is now saving through its relation question_opt…
2 parents 2268f47 + 647b1ba commit 758a586

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

app/controllers/answers_controller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class AnswersController < ApplicationController
66
# PUT/PATCH /[:locale]/answer/[:id]
77
def update
88
# create a new answer based off the passed params
9-
109
ans_params = params[:answer]
1110
plan_id = ans_params[:plan_id]
1211
phase_id = ans_params[:phase_id]
@@ -21,8 +20,9 @@ def update
2120

2221
# This is the first answer for the question
2322
if @answer.nil?
24-
@answer = Answer.new(params[:answer])
23+
@answer = Answer.new(permitted_params)
2524
@answer.text = params["answer-text-#{@answer.question_id}".to_sym]
25+
2626
authorize @answer
2727

2828
@answer.save
@@ -46,7 +46,7 @@ def update
4646
@answer.text = params["answer-text-#{@answer.question_id}".to_sym]
4747
authorize @answer
4848

49-
@answer.update(params[:answer])
49+
@answer.update(permitted_params)
5050

5151
# The save was successful so get the lock version and nil the
5252
# old answer
@@ -101,4 +101,7 @@ def update
101101
end
102102
end
103103

104+
def permitted_params
105+
params.require(:answer).permit(:id, :plan_id, :user_id, :question_id, :lock_version, :question_option_ids)
106+
end
104107
end

app/views/phases/_answer_form.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
<% options.each do |op| %>
6767
<li class= "choices-group">
6868
<% if answer.question_option_ids[0] == op.id then%>
69-
<%= f.radio_button :option_ids, op.id, checked: true, id: "answer_option_ids_#{op.id}"%>
69+
<%= f.radio_button :question_option_ids, op.id, checked: true, id: "answer_option_ids_#{op.id}"%>
7070
<%else%>
71-
<%= f.radio_button :option_ids, op.id, checked: false, id: "answer_option_ids_#{op.id}"%>
71+
<%= f.radio_button :question_option_ids, op.id, checked: false, id: "answer_option_ids_#{op.id}"%>
7272
<% end %>
7373
<%= raw op.text %> </li>
7474
<% end %>

0 commit comments

Comments
 (0)