Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2018 12:05
Show Gist options
  • Save anonymous/ef3df27bb1d13639ae387fe0d1b2af97 to your computer and use it in GitHub Desktop.
Save anonymous/ef3df27bb1d13639ae387fe0d1b2af97 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
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