From 434eb90b767f7bc371ce7232f52e7f4e0e2dcc4c Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Thu, 10 Mar 2016 14:25:38 +0530 Subject: [PATCH] Add flash type error.Rewrite controllers to use common flash style with redirect_to --- app/controllers/admin/campaigns_controller.rb | 18 +++++++++--------- .../admin/commercials_controller.rb | 10 ++++++---- app/controllers/admin/conference_controller.rb | 5 ++--- .../admin/difficulty_levels_controller.rb | 18 +++++++++--------- .../admin/event_types_controller.rb | 18 +++++++++--------- app/controllers/admin/questions_controller.rb | 3 +-- app/controllers/admin/roles_controller.rb | 12 ++++++------ app/controllers/admin/rooms_controller.rb | 16 ++++++++-------- app/controllers/admin/targets_controller.rb | 4 ++-- app/controllers/admin/tracks_controller.rb | 16 ++++++++-------- app/controllers/application_controller.rb | 8 ++++---- app/controllers/commercials_controller.rb | 8 ++++---- .../conference_registrations_controller.rb | 11 ++++++----- app/controllers/proposal_controller.rb | 3 +-- app/controllers/subscriptions_controller.rb | 12 ++++-------- .../users/omniauth_callbacks_controller.rb | 4 ++-- 16 files changed, 81 insertions(+), 85 deletions(-) diff --git a/app/controllers/admin/campaigns_controller.rb b/app/controllers/admin/campaigns_controller.rb index a7ace352..24e53e0c 100644 --- a/app/controllers/admin/campaigns_controller.rb +++ b/app/controllers/admin/campaigns_controller.rb @@ -12,8 +12,8 @@ module Admin @campaign.attributes = campaign_params if @conference.save - flash[:notice] = 'Campaign successfully created.' - redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title), + notice: 'Campaign successfully created.') else flash[:error] = 'Campaign creation failed. ' + @campaign.errors.full_messages.to_sentence render action: 'new' @@ -26,8 +26,8 @@ module Admin def update if @campaign.update_attributes(campaign_params) - flash[:notice] = "Campaign '#{@campaign.name}' successfully updated." - redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title), + notice: "Campaign '#{@campaign.name}' successfully updated.") else flash[:error] = "Campaign update failed. #{@campaign.errors.full_messages.to_sentence}" render action: 'edit' @@ -36,12 +36,12 @@ module Admin def destroy if @campaign.destroy - flash[:notice] = "Campaign '#{@campaign.name}' successfully deleted." - redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title), + notice: "Campaign '#{@campaign.name}' successfully deleted.") else - flash[:error] = "Delete of Campaign for #{@conference.short_title} failed." \ - "#{@campaign.errors.full_messages.join('. ')}." - redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title), + error: "Delete of Campaign for #{@conference.short_title} failed."\ + "#{@campaign.errors.full_messages.join('. ')}.") end end diff --git a/app/controllers/admin/commercials_controller.rb b/app/controllers/admin/commercials_controller.rb index be365e08..703423fe 100644 --- a/app/controllers/admin/commercials_controller.rb +++ b/app/controllers/admin/commercials_controller.rb @@ -18,8 +18,9 @@ module Admin redirect_to admin_conference_commercials_path, notice: 'Commercial was successfully created.' else - flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." - redirect_to admin_conference_commercials_path + redirect_to admin_conference_commercials_path, + error: 'An error prohibited this Commercial from being saved: '\ + "#{@commercial.errors.full_messages.join('. ')}." end end @@ -29,8 +30,9 @@ module Admin redirect_to admin_conference_commercials_path, notice: 'Commercial was successfully updated.' else - flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." - redirect_to admin_conference_commercials_path + redirect_to admin_conference_commercials_path, + error: 'An error prohibited this Commercial from being saved: '\ + "#{@commercial.errors.full_messages.join('. ')}." end end diff --git a/app/controllers/admin/conference_controller.rb b/app/controllers/admin/conference_controller.rb index 1c1045e9..d836433b 100644 --- a/app/controllers/admin/conference_controller.rb +++ b/app/controllers/admin/conference_controller.rb @@ -67,12 +67,11 @@ module Admin @conference = Conference.new(conference_params) if @conference.save - flash[:notice] = 'Conference was successfully created.' - # user that creates the conference becomes organizer of that conference current_user.add_role :organizer, @conference - redirect_to admin_conference_path(id: @conference.short_title) + redirect_to admin_conference_path(id: @conference.short_title), + notice: 'Conference was successfully created.' else flash[:error] = 'Could not create conference. ' + @conference.errors.full_messages.to_sentence render action: 'new' diff --git a/app/controllers/admin/difficulty_levels_controller.rb b/app/controllers/admin/difficulty_levels_controller.rb index 154fd3b6..f842ba26 100644 --- a/app/controllers/admin/difficulty_levels_controller.rb +++ b/app/controllers/admin/difficulty_levels_controller.rb @@ -17,8 +17,8 @@ module Admin def create @difficulty_level = @conference.program.difficulty_levels.new(difficulty_level_params) if @difficulty_level.save - flash[:notice] = 'Difficulty level successfully created.' - redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title), + notice: 'Difficulty level successfully created.') else flash[:error] = "Creating difficulty level failed: #{@difficulty_level.errors.full_messages.join('. ')}." render :new @@ -27,8 +27,8 @@ module Admin def update if @difficulty_level.update_attributes(difficulty_level_params) - flash[:notice] = 'Difficulty level successfully updated.' - redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title), + notice: 'Difficulty level successfully updated.') else flash[:error] = "Update difficulty level failed: #{@difficulty_level.errors.full_messages.join('. ')}." render :edit @@ -37,12 +37,12 @@ module Admin def destroy if @difficulty_level.destroy - flash[:notice] = 'Difficulty level successfully deleted.' - redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title), + notice: 'Difficulty level successfully deleted.') else - flash[:error] = 'Deleting difficulty level type failed! ' \ - "#{@difficulty_level.errors.full_messages.join('. ')}." - redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title), + error: 'Deleting difficulty level type failed! '\ + "#{@difficulty_level.errors.full_messages.join('. ')}.") end end diff --git a/app/controllers/admin/event_types_controller.rb b/app/controllers/admin/event_types_controller.rb index 18077040..64423abf 100644 --- a/app/controllers/admin/event_types_controller.rb +++ b/app/controllers/admin/event_types_controller.rb @@ -15,8 +15,8 @@ module Admin def create @event_type = @conference.program.event_types.new(event_type_params) if @event_type.save - flash[:notice] = 'Event type successfully created.' - redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title), + notice: 'Event type successfully created.') else flash[:error] = "Creating event type failed: #{@event_type.errors.full_messages.join('. ')}." render :new @@ -25,8 +25,8 @@ module Admin def update if @event_type.update_attributes(event_type_params) - flash[:notice] = 'Event type successfully updated.' - redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title), + notice: 'Event type successfully updated.') else flash[:error] = "Update event type failed: #{@event_type.errors.full_messages.join('. ')}." render :edit @@ -35,12 +35,12 @@ module Admin def destroy if @event_type.destroy - flash[:notice] = 'Event type successfully deleted.' - redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title), + notice: 'Event type successfully deleted.') else - flash[:error] = 'Destroying event type failed! ' \ - "#{@event_type.errors.full_messages.join('. ')}." - redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title), + error: 'Destroying event type failed! '\ + "#{@event_type.errors.full_messages.join('. ')}.") end end diff --git a/app/controllers/admin/questions_controller.rb b/app/controllers/admin/questions_controller.rb index 590182c3..310adfa2 100644 --- a/app/controllers/admin/questions_controller.rb +++ b/app/controllers/admin/questions_controller.rb @@ -32,8 +32,7 @@ module Admin if @conference.save format.html { redirect_to admin_conference_questions_path, notice: 'Question was successfully created.' } else - flash[:error] = "Oops, couldn't save Question. #{@question.errors.full_messages.join('. ')}" - format.html { redirect_to admin_conference_questions_path } + format.html { redirect_to admin_conference_questions_path, error: "Oops, couldn't save Question. #{@question.errors.full_messages.join('. ')}" } end end end diff --git a/app/controllers/admin/roles_controller.rb b/app/controllers/admin/roles_controller.rb index d99a1b96..8752d700 100644 --- a/app/controllers/admin/roles_controller.rb +++ b/app/controllers/admin/roles_controller.rb @@ -21,8 +21,8 @@ module Admin role_name = @role.name if @role.update_attributes(role_params) - flash[:notice] = 'Successfully updated role ' + @role.name - redirect_to admin_conference_role_path(@conference.short_title, @role.name) + redirect_to admin_conference_role_path(@conference.short_title, @role.name), + notice: 'Successfully updated role ' + @role.name else @role.name = role_name flash[:error] = 'Could not update role! ' + @role.errors.full_messages.to_sentence @@ -35,14 +35,14 @@ module Admin state = user_params[:state] unless user - flash[:error] = 'Could not find user. Please provide a valid email!' - redirect_to(admin_conference_role_path(@conference.short_title, @role.name)) && return + redirect_to(admin_conference_role_path(@conference.short_title, @role.name), + error: 'Could not find user. Please provide a valid email!') && return end # The conference must have at least 1 organizer if @role.name == 'organizer' && state == 'false' && @role.users.count == 1 - flash[:error] = 'The conference must have at least 1 organizer!' - redirect_to(admin_conference_role_path(@conference.short_title, @role.name)) && return + redirect_to(admin_conference_role_path(@conference.short_title, @role.name), + error: 'The conference must have at least 1 organizer!') && return end # Remove user diff --git a/app/controllers/admin/rooms_controller.rb b/app/controllers/admin/rooms_controller.rb index 2fda73d6..acedb00b 100644 --- a/app/controllers/admin/rooms_controller.rb +++ b/app/controllers/admin/rooms_controller.rb @@ -15,8 +15,8 @@ module Admin def create @room = @venue.rooms.new(room_params) if @room.save - flash[:notice] = 'Room successfully created.' - redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title), + notice: 'Room successfully created.') else flash[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}." render :new @@ -25,8 +25,8 @@ module Admin def update if @room.update_attributes(room_params) - flash[:notice] = 'Room successfully updated.' - redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title), + notice: 'Room successfully updated.') else flash[:error] = "Update Room failed: #{@room.errors.full_messages.join('. ')}." render :edit @@ -35,11 +35,11 @@ module Admin def destroy if @room.destroy - flash[:notice] = 'Room successfully deleted.' - redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title), + notice: 'Room successfully deleted.') else - flash[:error] = "Destroying room failed! #{@room.errors.full_messages.join('. ')}." - redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_venue_rooms_path(conference_id: @conference.short_title), + error: "Destroying room failed! #{@room.errors.full_messages.join('. ')}.") end end diff --git a/app/controllers/admin/targets_controller.rb b/app/controllers/admin/targets_controller.rb index d15d5726..25acc9c1 100644 --- a/app/controllers/admin/targets_controller.rb +++ b/app/controllers/admin/targets_controller.rb @@ -38,8 +38,8 @@ module Admin notice: 'Target successfully destroyed.') else redirect_to admin_conference_targets_path(conference_id: @conference.short_title), - flash: { error: "Could not delete target for #{@conference.title}: "\ - "#{@target.errors.full_messages.join('. ')}." } + error: "Could not delete target for #{@conference.title}: "\ + "#{@target.errors.full_messages.join('. ')}." end end diff --git a/app/controllers/admin/tracks_controller.rb b/app/controllers/admin/tracks_controller.rb index 68777913..1371039f 100644 --- a/app/controllers/admin/tracks_controller.rb +++ b/app/controllers/admin/tracks_controller.rb @@ -20,8 +20,8 @@ module Admin def create @track = @program.tracks.new(track_params) if @track.save - flash[:notice] = 'Track successfully created.' - redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title), + notice: 'Track successfully created.') else flash[:error] = "Creating Track failed: #{@track.errors.full_messages.join('. ')}." render :new @@ -32,8 +32,8 @@ module Admin def update if @track.update_attributes(track_params) - flash[:notice] = 'Track successfully updated.' - redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title), + notice: 'Track successfully updated.') else flash[:error] = "Track update failed: #{@track.errors.full_messages.join('. ')}." render :edit @@ -42,11 +42,11 @@ module Admin def destroy if @track.destroy - flash[:notice] = 'Track successfully deleted.' - redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title), + notice: 'Track successfully deleted.') else - flash[:error] = "Track couldn't be deleted. #{@track.errors.full_messages.join('. ')}." - redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title)) + redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title), + error: "Track couldn't be deleted. #{@track.errors.full_messages.join('. ')}.") end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a0d87498..51dc6772 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base include ApplicationHelper + add_flash_types :error protect_from_forgery with: :exception before_filter :get_conferences before_filter :store_location @@ -52,16 +53,15 @@ class ApplicationController < ActionController::Base rescue_from IChainRecordNotFound do Rails.logger.debug('IChain Record was not Unique!') sign_out(current_user) - flash[:error] = 'Your E-Mail adress is already registered at OSEM. Please contact the admin if you want to attach your openSUSE Account to OSEM!' - redirect_to root_path + redirect_to root_path, + error: 'Your E-Mail adress is already registered at OSEM. Please contact the admin if you want to attach your openSUSE Account to OSEM!' end rescue_from UserDisabled do Rails.logger.debug('User is disabled!') sign_out(current_user) mail = User.admin.first ? User.admin.first.email : 'the admin!' - flash[:error] = "This User is disabled. Please contact #{mail}!" - redirect_to User.ichain_logout_url + redirect_to User.ichain_logout_url, error: "This User is disabled. Please contact #{mail}!" end def not_found diff --git a/app/controllers/commercials_controller.rb b/app/controllers/commercials_controller.rb index c36feedc..69a235a4 100644 --- a/app/controllers/commercials_controller.rb +++ b/app/controllers/commercials_controller.rb @@ -11,8 +11,8 @@ class CommercialsController < ApplicationController redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), notice: 'Commercial was successfully created.' else - flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." - redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content') + redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), + error: "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." end end @@ -21,8 +21,8 @@ class CommercialsController < ApplicationController redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), notice: 'Commercial was successfully updated.' else - flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." - redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content') + redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), + error: "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." end end diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index c9d7d216..c3fb0f6d 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -60,11 +60,12 @@ class ConferenceRegistrationsController < ApplicationController sign_in(@registration.user) end - flash[:notice] = 'You are now registered and will be receiving E-Mail notifications.' if @conference.tickets.any? && !current_user.supports?(@conference) - redirect_to conference_tickets_path(@conference.short_title) + redirect_to conference_tickets_path(@conference.short_title), + notice: 'You are now registered and will be receiving E-Mail notifications.' else - redirect_to conference_conference_registrations_path(@conference.short_title) + redirect_to conference_conference_registrations_path(@conference.short_title), + notice: 'You are now registered and will be receiving E-Mail notifications.' end else flash[:error] = "Could not create your registration for #{@conference.title}: "\ @@ -100,8 +101,8 @@ class ConferenceRegistrationsController < ApplicationController def set_registration @registration = Registration.find_by(conference: @conference, user: current_user) if !@registration - flash[:alert] = "Can't find a registration for #{@conference.title} for you. Please register." - redirect_to new_conference_conference_registrations_path(@conference.short_title) + redirect_to new_conference_conference_registrations_path(@conference.short_title), + alert: "Can't find a registration for #{@conference.title} for you. Please register." end end diff --git a/app/controllers/proposal_controller.rb b/app/controllers/proposal_controller.rb index 82706e64..cc1bbe0c 100644 --- a/app/controllers/proposal_controller.rb +++ b/app/controllers/proposal_controller.rb @@ -55,8 +55,7 @@ class ProposalController < ApplicationController ahoy.track 'Event submission', title: 'New submission' - flash[:notice] = 'Proposal was successfully submitted.' - redirect_to conference_program_proposal_index_path(@conference.short_title) + redirect_to conference_program_proposal_index_path(@conference.short_title), notice: 'Proposal was successfully submitted.' end def update diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 6d5b7cdf..351f9e9d 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -6,22 +6,18 @@ class SubscriptionsController < ApplicationController def create @subscription = current_user.subscriptions.build(conference_id: @conference.id) if @subscription.save! - flash[:notice] = "You have been subscribed to receive email notifications for #{@conference.short_title}." - redirect_to root_path + redirect_to root_path, notice: "You have been subscribed to receive email notifications for #{@conference.short_title}." else - flash[:error] = subscription.errors.full_messages.to_sentence - redirect_to root_path + redirect_to root_path, error: subscription.errors.full_messages.to_sentence end end def destroy @subscription = current_user.subscriptions.find_by(conference_id: @conference.id) if @subscription.destroy - flash[:notice] = "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}." - redirect_to root_path + redirect_to root_path, notice: "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}." else - flash[:error] = @subscription.errors.full_messages.to_sentence - redirect_to root_path + redirect_to root_path, error: @subscription.errors.full_messages.to_sentence end end end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index ec42b3e2..cf6eb6a8 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -28,8 +28,8 @@ module Users openid.save! sign_in user - flash[:notice] = "#{user.email} signed in successfully with #{provider}" - redirect_to request.env['omniauth.origin'] || root_path + redirect_to request.env['omniauth.origin'] || root_path, + notice: "#{user.email} signed in successfully with #{provider}" rescue => e flash[:error] = e.message redirect_back_or_to new_user_registration_path