class QuestionsController < ApplicationController
# ...
# GET questions/:id/edit
def edit
@question = Question.find(params[:id])
@redirect_url = redirect_url
end
# PATCH questions/:id
def update
@question = Question.find(params[:id])
@question.answer = params[:question][:answer]
if @question.save
flash[:success] = "Answer was successfully saved"
redirect_to redirect_url
else
@redirect_url = redirect_url
render :edit
end
end
# ...
private
def redirect_url
params[:redirect_url].presence || pulse_questions_url
end
#...
end
- redirect_url = property_url(@property)
.panel
.panel-heading
h4.panel-title
| Questions
.panel-collapse
.panel-body
.form-wrapper
h3 Questions
table
thead
tr
th Questioner
th Question
th Answer
tbody
- @questions.each do |question|
tr
td
= Mail::Address.new("#{question.questioner_name} <#{question.questioner_email}>").to_s
br
| #{time_ago_in_words(question.created_at)} ago
td
= question.question
td
- if question.answered?
= question.answer
- elsif question.answer.present?
a[href="#{edit_question_path(question, redirect_url: redirect_url)}"]
= question.answer
- else
a.btn.btn-sm.btn-primary[
href="#{edit_question_path(question, redirect_url: redirect_url)}"
| Answer
= content_for :page_header do
h1 Answer
= simple_form_for @question do |f|
= hidden_field_tag :redirect_url, @redirect_url
= f.input :answer, as: :text, label: "Answer"
div
= link_to "Back", @redirect_url, class: "btn btn-default btn-sm"
= f.button(:submit, "Answer question", class: "btn btn-primary btn-sm")