Sha256: a05409e886dd086e3145c6aea524c85a6ccdf6183a29bfdcd2e104ce4ed37d6c

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true
module Thredded
  class PreferencesController < Thredded::ApplicationController
    before_action :thredded_require_login!,
                  :init_preferences

    def edit
    end

    def update
      if @preferences.save
        flash[:notice] = t('thredded.preferences.updated_notice')
        redirect_back fallback_location: edit_preferences_url(@preferences.messageboard)
      else
        render :edit
      end
    end

    private

    def init_preferences
      @preferences = UserPreferencesForm.new(
        user:         thredded_current_user,
        messageboard: messageboard_or_nil,
        params: preferences_params
      )
    end

    def preferences_params
      params.fetch(:user_preferences_form, {}).permit(
        :follow_topics_on_mention,
        :messageboard_follow_topics_on_mention,
        messageboard_notifications_for_followed_topics_attributes: %i(notifier_key id messageboard_id enabled),
        notifications_for_followed_topics_attributes: %i(notifier_key id enabled),
        notifications_for_private_topics_attributes: %i(notifier_key id enabled)
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thredded-0.10.0 app/controllers/thredded/preferences_controller.rb
thredded-0.9.4 app/controllers/thredded/preferences_controller.rb
thredded-0.9.3 app/controllers/thredded/preferences_controller.rb
thredded-0.9.2 app/controllers/thredded/preferences_controller.rb
thredded-0.9.1 app/controllers/thredded/preferences_controller.rb