clarion/app/controllers/public/conference_feedbacks_contro...

43 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

2017-10-22 23:40:12 +03:00
class Public::ConferenceFeedbacksController < Public::ApplicationController
def index
@conference = current_conference
@unrated_events = @conference.events
2019-04-28 21:10:54 +03:00
.joins(:proposition).approved
.joins("LEFT JOIN feedbacks ON feedbacks.feedback_receiving_id = events.id AND feedbacks.feedback_receiving_type = 'Event'")
2022-10-19 01:42:37 +03:00
.where("feedbacks.session_id != ? OR feedbacks.id IS NULL", session.id.to_s).distinct
@rated_events = @conference.events
2019-04-28 21:10:54 +03:00
.joins(:proposition).approved
.joins(:feedbacks)
2022-10-19 01:42:37 +03:00
.where(feedbacks: {session_id: session.id.to_s}).distinct
end
2017-10-22 23:40:12 +03:00
def new
2022-10-19 01:42:37 +03:00
if current_conference.feedbacks.where(session_id: session.id.to_s).exists?
@feedback = current_conference.feedbacks.where(session_id: session.id.to_s).order(updated_at: :asc).last
else
@feedback = current_conference.feedbacks.build
2022-10-19 01:42:37 +03:00
@feedback.author_email = Feedback.where(session_id: session.id.to_s).order(updated_at: :asc).last.try(:author_email)
end
2017-10-22 23:40:12 +03:00
end
def create
@feedback = current_conference.feedbacks.build(feedback_params)
@feedback.ip_address = request.remote_ip
2022-10-19 01:42:37 +03:00
@feedback.session_id = session.id.to_s
2017-10-22 23:40:12 +03:00
if @feedback.save
2019-04-28 21:10:54 +03:00
flash[:notice] = I18n.t("public.conference_feedbacks.new.success")
redirect_to conference_feedbacks_path
2017-10-22 23:40:12 +03:00
else
render :new, status: :unprocessable_entity
end
end
private
def feedback_params
params.require(:feedback).permit(:author_email, :rating, :comment)
end
end