Class: Trackguard::Admin::WhitelistedIpsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Trackguard::Admin::WhitelistedIpsController
- Defined in:
- app/controllers/trackguard/admin/whitelisted_ips_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/trackguard/admin/whitelisted_ips_controller.rb', line 14 def create record = WhitelistedIp.find_or_initialize_by(ip: @visitor.ip) record.visitor = @visitor record.expires_at = params[:expires_at].presence || 7.days.from_now record.save! respond_to do |format| format.html { redirect_back_or_to dashboard_path } format.json { render json: { status: "ok", ip: @visitor.ip, expires_at: record.expires_at } } end rescue ActiveRecord::RecordInvalid => e respond_to do |format| format.html { redirect_back_or_to dashboard_path, alert: e. } format.json { render json: { status: "error", message: e. }, status: :unprocessable_entity } end end |
#destroy ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/trackguard/admin/whitelisted_ips_controller.rb', line 30 def destroy record = @visitor.whitelisted_ip if record record.destroy! respond_to do |format| format.html { redirect_back_or_to dashboard_path } format.json { render json: { status: "ok", ip: @visitor.ip } } end else respond_to do |format| format.html { redirect_back_or_to dashboard_path, alert: "No whitelist entry found." } format.json { render json: { error: "Not whitelisted" }, status: :not_found } end end end |