From 39217a24c1d6b2788fc8af92143ac92c6d6a4a66 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 22 Oct 2017 23:40:12 +0300 Subject: [PATCH] Introduce conference feedback --- .../public/conference_feedbacks_controller.rb | 24 +++++++++++++++++++ .../public/event_feedbacks_controller.rb | 3 +++ config/locales/bg.yml | 4 +++- config/locales/en.yml | 4 +++- config/routes.rb | 3 ++- .../public/conference_feedbacks/new.html.slim | 14 +++++++++++ 6 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 app/controllers/public/conference_feedbacks_controller.rb create mode 100644 lib/initfest/views/public/conference_feedbacks/new.html.slim diff --git a/app/controllers/public/conference_feedbacks_controller.rb b/app/controllers/public/conference_feedbacks_controller.rb new file mode 100644 index 0000000..dc3b677 --- /dev/null +++ b/app/controllers/public/conference_feedbacks_controller.rb @@ -0,0 +1,24 @@ +class Public::ConferenceFeedbacksController < Public::ApplicationController + def new + @feedback = current_conference.feedbacks.build + end + + def create + @feedback = current_conference.feedbacks.build(feedback_params) + @feedback.ip_address = request.remote_ip + @feedback.session_id = session.id + + if @feedback.save + flash[:notice] = I18n.t('public.conference_feedbacks.new.success') + 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 +end diff --git a/app/controllers/public/event_feedbacks_controller.rb b/app/controllers/public/event_feedbacks_controller.rb index b857484..f2246da 100644 --- a/app/controllers/public/event_feedbacks_controller.rb +++ b/app/controllers/public/event_feedbacks_controller.rb @@ -5,8 +5,11 @@ class Public::EventFeedbacksController < Public::ApplicationController def create @feedback = approved_events.find(params[:event_id]).feedbacks.build(feedback_params) + @feedback.ip_address = request.remote_ip + @feedback.session_id = session.id if @feedback.save + flash[:notice] = I18n.t('public.event_feedbacks.new.success') redirect_to root_path else render :new, status: :unprocessable_entity diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 497e092..0a643ab 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1,9 +1,11 @@ bg: public: - event_feedbacks: + event_feedbacks: &feedbacks_bg new: feedback_for: Оценяване на „%{title}“ submit: Изпрати + success: Оценката беше изпратена успешно + conference_feedbacks: *feedbacks_bg management: volunteers: index: diff --git a/config/locales/en.yml b/config/locales/en.yml index 7efef82..6215436 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,9 +1,11 @@ en: public: - event_feedbacks: + event_feedbacks: &feedbacks_en new: feedback_for: Rating '%{title}' submit: Submit + success: The feedback was submitted successfully + conference_feedbacks: *feedbacks_en abstract: Abstract helpers: submit: diff --git a/config/routes.rb b/config/routes.rb index 7167f63..1bcb44a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +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] + resources :feedback, controller: 'event_feedbacks', only: [:new, :create] resource :feedback_qr_code, controller: 'event_feedback_qrcodes', only: :show member do get :confirm @@ -13,6 +13,7 @@ Rails.application.routes.draw do end resources :volunteers resources :volunteer_teams, only: [:index] + resources :feedback, as: 'conference_feedbacks', controller: 'conference_feedbacks', only: [:new, :create] end namespace :api do diff --git a/lib/initfest/views/public/conference_feedbacks/new.html.slim b/lib/initfest/views/public/conference_feedbacks/new.html.slim new file mode 100644 index 0000000..03e4028 --- /dev/null +++ b/lib/initfest/views/public/conference_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: conference_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')