Skip to content

Instantly share code, notes, and snippets.

@xhoy
Forked from anonymous/controller.rb
Last active January 24, 2018 12:08
Show Gist options
  • Save xhoy/97ffb8113eb166f0d0f4728f2159914f to your computer and use it in GitHub Desktop.
Save xhoy/97ffb8113eb166f0d0f4728f2159914f to your computer and use it in GitHub Desktop.
class UnApprovedActions < ApplicationController
def approve_action
Action.find_by(token: params[:token], *other stuff*).run_action
end
end
class UnApprovedActions < ActiveRecord::Migration[5.0]
def change
create_table :un_approved_actions do |t|
t.references :imageable, polymorphic: true, index: true
t.string :action, allow_nil: false
t.references :users, allow_nil: false
t.string :token, index: true, uniq: true, allow_nil: false
t.timestamps
end
add_index :un_approved_actions, [:holder_type, :holder_id], uniq: true
end
end
class UnApprovedActions < ApplicationRecord
belongs_to :holder, polymorphic: true
validates_presence_of :holder, :action, :user, :token
def run_action
whitelist_classes %w{invoices, quotes} #think about classname with Caps etc
if whitelist_class.includes?(holder_type)
holder.public_send(action)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment