Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created April 16, 2015 14:58
Show Gist options
  • Save dgmike/afb9ab23315723623167 to your computer and use it in GitHub Desktop.
Save dgmike/afb9ab23315723623167 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment