1class FeedbackController < ApplicationController |
|
2 before_action :build_feedback, only: [:new, :create] |
|
|
4 def new |
5 respond_to do |format| |
|
6 format.html
|
|
7 end |
|
8 end |
|
|
10 def create |
11 if @feedback.save |
|
12 FeedbackEmailJob.perform_later(@feedback) |
|
13 redirect_to thanks_feedback_url
|
|
14 else |
|
15 respond_to do |format| |
|
16 format.html { render :new } |
|
17 end |
|
18 end |
|
19 end |
|
|
21 def thanks |
22 respond_to do |format| |
|
23 format.html
|
|
24 end |
|
25 end |
|
27 private
|
|
|
29 def build_feedback |
30 @feedback = Feedback.new(params.key?(:feedback) ? feedback_params : {}) |
|
31 end |
|
|
33 def feedback_params |
34 params.require(:feedback).permit(*feedback_attributes).merge(user_agent) |
|
35 end |
|
|
37 def feedback_attributes |
38 [:email, :petition_link_or_title, :comment] |
|
39 end |
|
|
41 def user_agent |
42 { user_agent: request.user_agent } |
|
43 end |
|
44end |