diff --git a/app/controllers/public/event_feedbacks_controller.rb b/app/controllers/public/event_feedbacks_controller.rb new file mode 100644 index 0000000..b857484 --- /dev/null +++ b/app/controllers/public/event_feedbacks_controller.rb @@ -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 diff --git a/app/models/conference.rb b/app/models/conference.rb index 47eeb30..4b9532f 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index dc60733..62c18d8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/models/feedback.rb b/app/models/feedback.rb new file mode 100644 index 0000000..99a90e0 --- /dev/null +++ b/app/models/feedback.rb @@ -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 diff --git a/app/views/api/events/index.jbuilder b/app/views/api/events/index.jbuilder index 543b195..72f5a0b 100644 --- a/app/views/api/events/index.jbuilder +++ b/app/views/api/events/index.jbuilder @@ -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 diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 88cf97d..497e092 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -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 на организаторския екип diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a48fdb..7efef82 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index d0663bb..893252b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20171022182011_create_feedbacks.rb b/db/migrate/20171022182011_create_feedbacks.rb new file mode 100644 index 0000000..606dbe7 --- /dev/null +++ b/db/migrate/20171022182011_create_feedbacks.rb @@ -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 diff --git a/lib/initfest/views/public/event_feedbacks/new.html.slim b/lib/initfest/views/public/event_feedbacks/new.html.slim new file mode 100644 index 0000000..02c6d61 --- /dev/null +++ b/lib/initfest/views/public/event_feedbacks/new.html.slim @@ -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') diff --git a/lib/initfest/views/public/event_feedbacks/show.html.slim b/lib/initfest/views/public/event_feedbacks/show.html.slim new file mode 100644 index 0000000..3603360 --- /dev/null +++ b/lib/initfest/views/public/event_feedbacks/show.html.slim @@ -0,0 +1 @@ +p Hello