Looking at my last post, this is my modification:
It took me a while to figure out that I have to store data in a session variable in order to trigger another action. But now I can create a new view with a more precise view of answered questions etc.
And to get your custom action through REST:
# POST /diagnoses
# POST /diagnoses.json
def create
#flash[:message] = params[:question_ids]
# ["1 2", "2 1", "3 2"]
right = []
result = []
params[:question_ids].each do |p|
result = p.gsub(/\s+/m, ' ').strip.split(" ")
if result[1] == Question.find(result[0].to_i).right.to_s then right << result[0] end
end
if right.empty?
r = "0"
else r = right.size end
flash[:message] = "Richtig sind: " + r.to_s #+ params[:question_ids].to_s + "result: " + result.to_s
session[:tmp_diagnosis_raw] = params[:question_ids]
session[:tmp_diagnosis_right] = right
redirect_to diagnosed_diagnoses_path
end
def diagnosed
@diagnosed_raw = session[:tmp_diagnosis_raw]
@diagnosed_right = session[:tmp_diagnosis_right].size.to_s
end
It took me a while to figure out that I have to store data in a session variable in order to trigger another action. But now I can create a new view with a more precise view of answered questions etc.
And to get your custom action through REST:
resources :diagnoses do
collection do
get 'diagnosed'
post 'create'
get 'index'
end
end
Kommentare
Kommentar veröffentlichen