Skip to content

Instantly share code, notes, and snippets.

@jmercedes
Created May 24, 2015 13:43
Show Gist options
  • Select an option

  • Save jmercedes/85886eebcf07fdf02b24 to your computer and use it in GitHub Desktop.

Select an option

Save jmercedes/85886eebcf07fdf02b24 to your computer and use it in GitHub Desktop.
module Refinery
module Testimonies
module Admin
class SettingsController < Refinery::AdminController
before_action :check_setting, :only => [:edit, :update]
after_action :save_subject_for_confirmation, :save_message_for_confirmation, :only => :update
def edit
@setting = Refinery::Setting.find(params[:id])
end
def update
@setting = Refinery::Setting.find(params[:id])
if @setting.update_attributes(params[:setting])
flash[:notice] = t('refinery.crudify.updated', :what => @setting.name.gsub("testimony_", "").titleize)
if request.xhr? or from_dialog?
render :text => "<script type='text/javascript'>parent.window.location = '#{refinery.testimonies_admin_testimonies_path}';</script>"
else
redirect_back_or_default(refinery.testimonies_admin_testimonies_path)
end
end
end
protected
def check_setting
setting = params[:id].gsub("testimony_", "")
Refinery::Testimonies::Setting.send(setting) if Refinery::Testimonies::Setting.respond_to?(setting)
end
def save_subject_for_confirmation
Refinery::Testimonies::Setting.confirmation_subject = params[:subject] if params.keys.include?('subject')
end
def save_message_for_confirmation
Refinery::Testimonies::Setting.confirmation_message = params[:message] if params.keys.include?('message')
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment