diff options
author | David Yip <yipdw@member.fsf.org> | 2017-10-20 15:12:45 -0500 |
---|---|---|
committer | David Yip <yipdw@member.fsf.org> | 2017-10-21 14:54:36 -0500 |
commit | cd04e3df58c09b0faca81ccc820b2cd5e12c2890 (patch) | |
tree | 932e00860dc94c03712222ba68bed19480e0a3b6 /app/controllers | |
parent | 4a64181461cb02599da98166da4b527adbb705ad (diff) |
Fill in create, edit, update, and destroy for keyword mutes interface.
Also add a destroy-all action, which can be useful if you're flushing an old list entirely to start a new one.
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/settings/keyword_mutes_controller.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/controllers/settings/keyword_mutes_controller.rb b/app/controllers/settings/keyword_mutes_controller.rb index 4b3e01b9c..d9f99af09 100644 --- a/app/controllers/settings/keyword_mutes_controller.rb +++ b/app/controllers/settings/keyword_mutes_controller.rb @@ -5,6 +5,7 @@ class Settings::KeywordMutesController < ApplicationController before_action :authenticate_user! before_action :set_account + before_action :load_keyword_mute, only: [:edit, :update, :destroy] def index @keyword_mutes = paginated_keyword_mutes_for_account @@ -14,6 +15,39 @@ class Settings::KeywordMutesController < ApplicationController @keyword_mute = keyword_mutes_for_account.build end + def create + @keyword_mute = keyword_mutes_for_account.create(keyword_mute_params) + + if @keyword_mute.persisted? + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + else + render :new + end + end + + def update + if @keyword_mute.update(keyword_mute_params) + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + else + render :new + end + end + + def destroy + if @keyword_mute.destroy + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + else + # FIXME + redirect_to settings_keyword_mutes_path, notice: "huh that didn't work right" + end + end + + def destroy_all + keyword_mutes_for_account.delete_all + + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + end + private def set_account @@ -24,6 +58,14 @@ class Settings::KeywordMutesController < ApplicationController KeywordMute.where(account: @account) end + def load_keyword_mute + @keyword_mute = keyword_mutes_for_account.find(params[:id]) + end + + def keyword_mute_params + params.require(:keyword_mute).permit(:keyword, :whole_word) + end + def paginated_keyword_mutes_for_account keyword_mutes_for_account.order(:keyword).page params[:page] end |