Introduce feedbacks for events

This commit is contained in:
Petko Bordjukov 2017-10-22 22:38:48 +03:00
parent 2ac4464d1b
commit 3384a73204
11 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,25 @@
class Public::EventFeedbacksController < Public::ApplicationController
def new
@feedback = approved_events.find(params[:event_id]).feedbacks.build
end
def create
@feedback = approved_events.find(params[:event_id]).feedbacks.build(feedback_params)
if @feedback.save
redirect_to root_path
else
render :new, status: :unprocessable_entity
end
end
private
def feedback_params
params.require(:feedback).permit(:author_email, :rating, :comment)
end
def approved_events
current_conference.events.joins(:proposition).approved
end
end

View File

@ -22,6 +22,7 @@ class Conference < ActiveRecord::Base
has_many :participants, -> { uniq }, class_name: 'User', through: :events
has_many :participant_profiles, class_name: 'PersonalProfile'
has_many :slots, through: :halls
has_many :feedbacks, as: :feedback_receiving, dependent: :destroy
accepts_nested_attributes_for :tracks, :halls, :event_types, :volunteer_teams,
reject_if: :all_blank, allow_destroy: true

View File

@ -11,6 +11,7 @@ class Event < ActiveRecord::Base
has_many :participants, through: :approved_participations
has_many :participants_with_personal_profiles, through: :approved_participations, source: :participant_with_personal_profile
has_many :conflict_counts, -> { order(number_of_conflicts: :desc) }, foreign_key: :left_id
has_many :feedbacks, as: :feedback_receiving, dependent: :destroy
belongs_to :event_type

5
app/models/feedback.rb Normal file
View File

@ -0,0 +1,5 @@
class Feedback < ActiveRecord::Base
belongs_to :feedback_receiving, polymorphic: true
validates :rating, presence: true, inclusion: {in: [2, 3, 4, 5 ,6]}
end

View File

@ -9,5 +9,6 @@
json.event_type_id event.event_type_id
json.track_id event.track_id
json.participant_user_ids event.participations.map(&:participant_id)
json.feedback_url new_event_feedback_url(event_id: event.id)
end
end

View File

@ -1,4 +1,9 @@
bg:
public:
event_feedbacks:
new:
feedback_for: Оценяване на „%{title}“
submit: Изпрати
management:
volunteers:
index:
@ -103,6 +108,10 @@ bg:
title: "Преглед на %{model}"
activerecord:
attributes:
feedback:
author_email: E-mail
rating: Оценка
comment: Коментар
participation:
participant: Участник
approved: Потвърдено от участника
@ -208,6 +217,9 @@ bg:
volunteer_teams:
invalid_volunteer_team: "невалиден екип от доброволци"
models:
feedback:
one: Оценка
other: Оценки
participation:
one: Участие
other: Участия
@ -372,6 +384,10 @@ bg:
vegetarian: Вегетарианец
vegan: Веган
hints:
feedback:
author_email: Адресът на електронната ви поща, ако счетете за нужно
rating: Посочете оценката си
comment: Тук може да изразите по-подробно мнението си
conference:
description: "Описание на конференцията"
email: Email на организаторския екип

View File

@ -1,4 +1,9 @@
en:
public:
event_feedbacks:
new:
feedback_for: Rating '%{title}'
submit: Submit
abstract: Abstract
helpers:
submit:
@ -29,6 +34,10 @@ en:
title: Viewing %{model}
activerecord:
attributes:
feedback:
author_email: E-mail
rating: Rating
comment: Comment
conference:
description: Description
email: E-mail
@ -271,6 +280,10 @@ en:
vegetarian: Vegetarian
vegan: Vegan
hints:
feedback:
author_email: "Your E-mail address if you'd like to share it with us"
rating: Select your rating for the event
comment: Express your opinion in greater detail here
conference:
description: Conference description
email: Orga team email

View File

@ -5,6 +5,7 @@ Rails.application.routes.draw do
root to: 'home#index'
resource :personal_profile, path: 'profile'
resources :events do
resources :feedbacks, controller: 'event_feedbacks', only: [:new, :create]
member do
get :confirm
end

View File

@ -0,0 +1,14 @@
class CreateFeedbacks < ActiveRecord::Migration
def change
create_table :feedbacks do |t|
t.references :feedback_receiving, index: {name: :feedbacks_polymorphic_index}, polymorphic: true, null: false
t.string :author_email
t.integer :rating, null: false
t.text :comment, null: false
t.string :ip_address
t.string :session_id, index: true
t.timestamps null: false
end
end
end

View File

@ -0,0 +1,14 @@
- content_for(:title) { t('.feedback_for', title: @feedback.feedback_receiving.title) }
h1.entry-title = t('.feedback_for', title: @feedback.feedback_receiving.title)
= simple_form_for @feedback, wrapper: :default, url: event_feedbacks_path do |f|
= f.error_notification
.form-inputs
= f.input :author_email, autofocus: true
= f.input :rating, collection: [2, 3, 4, 5, 6], as: :radio_buttons, include_blank: false, wrapper: :default
= f.input :comment
.form-actions
= f.button :submit, t('.submit')

View File

@ -0,0 +1 @@
p Hello