Created
January 24, 2018 12:05
-
-
Save anonymous/ef3df27bb1d13639ae387fe0d1b2af97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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 | |
end | |
end |
This file contains hidden or 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