ruby RoR:创建选项操作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby RoR:创建选项操作相关的知识,希望对你有一定的参考价值。

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

以上是关于ruby RoR:创建选项操作的主要内容,如果未能解决你的问题,请参考以下文章