dgmike
4/16/2015 - 2:58 PM

RoR: Create options actions

RoR: Create options actions

module Optionable
  extend ActiveSupport::Concern

  included do
    def self.options(action, allowed)
      send :define_method, "#{action}_options" do
        puts "Allow: #{allowed}"
      end
    end
  end
end

class PeopleController
  include Optionable
  
  options :index, "GET"
  def index
    # action methods
  end
end

# [3] pry(main)> people = PeopleController.new
# => #<People:0x007f97cbfaa6d0>
# [4] pry(main)> people.index_options
# Allow: GET