-
-
Save xhoy/97ffb8113eb166f0d0f4728f2159914f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnApprovedActions < ApplicationController | |
def approve_action | |
Action.find_by(token: params[:token], *other stuff*).run_action | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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