Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 有没有办法在Rails资源中包含外部参数块?_Ruby On Rails_Ruby_Refactoring_Grape - Fatal编程技术网

Ruby on rails 有没有办法在Rails资源中包含外部参数块?

Ruby on rails 有没有办法在Rails资源中包含外部参数块?,ruby-on-rails,ruby,refactoring,grape,Ruby On Rails,Ruby,Refactoring,Grape,我正在使用RubyonRails4和Grape 我希望我的葡萄资源占用一点空间,以便其他开发人员更容易阅读 在过去几天中,我们一直在集成StripeAPI(作为一个示例) 在参考资料的参数do部分,有如下代码块: desc 'Add bank account' do headers API::V1::Defaults.xxxxxxx success API::V1::Entities::xxxxxxx end params do requires :external_acc

我正在使用RubyonRails4和Grape

我希望我的葡萄资源占用一点空间,以便其他开发人员更容易阅读

在过去几天中,我们一直在集成StripeAPI(作为一个示例) 在参考资料的参数do部分,有如下代码块:

desc 'Add bank account' do
    headers API::V1::Defaults.xxxxxxx
    success API::V1::Entities::xxxxxxx
end

params do
  requires :external_account, type: Hash, allow_blank: false, desc: 'Bank account nested data' do
    requires :bank_account, type: Hash, allow_blank: false, desc: 'Bank account nested data' do
      requires :id, type: String, desc: 'Stripe token for bank account'
      requires :account_holder_name, type: String, desc: 'Bank account holder name'
      requires :account_holder_type, type: String, desc: 'Bank account holder type [individual or company]'
      optional :bank_name, type: String, desc: 'Bank name'
      requires :country, type: String, desc: 'Bank account country'
      optional :currency, type: String, desc: 'Bank account currency'
      requires :routing_number, type: String, desc: 'Bank account routing number'
      requires :name, type: String, desc: 'Bank account holders name'
      requires :status, type: String, desc: 'Bank account status'
      requires :last4, type: Integer,
                  desc: 'Account holder ID number.'
    end
    requires :client_ip, type: String, desc: 'IP address of user for Stripe service agreement'
  end
  requires :email, type: String, desc: 'Users email'
  requires :business_type, type: String, desc: 'Individual or Company'
  requires :tos_acceptance, type: Hash, allow_blank: false, desc: 'Type of Service' do
    requires :date, type: Integer, desc: 'ToS [date]'
    requires :ip, type: String, desc: 'ToS [ip]'
  end
  optional :individual, type: Hash do
    requires :first_name, type: String, desc: 'Individuals [first name]'
    requires :last_name, type: String, desc: 'Individuals [last name]'
    requires :ssn_last_4, type: String, desc: 'Individuals SSN number'
    optional :dob, type: Hash do
      requires :day, type: String, desc: 'Individuals date of birth [day]'
      requires :month, type: String, desc: 'Individuals date of birth [month]'
      requires :year, type: String, desc: 'Individuals date of birth [year]'
    end
  end
  optional :company, type: Hash do
    requires :name, type: String, desc: 'Company [first name]'
    requires :email, type: String, desc: 'Company [email]'
    requires :phone, type: String, desc: 'Company [phone]'
  end
end

# ...
oauth2
post '/' do
   # ...
end

如何使params块转到另一个文件(例如,在helpers文件夹中的文件中),并且可以包含params块


我尝试使用
include API::V1::Helpers::my_helper
执行此操作,但我不知道如何插入参数块。有人能帮我吗?

您可以使用共享参数

module SharedParams
  extend Grape::API::Helpers

  params :pagination do
    optional :page, type: Integer
    optional :per_page, type: Integer
  end
end

class API < Grape::API
  helpers SharedParams

  desc 'Get collection.'
  params do
    use :pagination
  end

  get do
    # your logic here
  end
end
模块共享参数
扩展Grape::API::Helpers
参数:分页do
可选:页面,类型:整数
可选:每页,类型:整数
结束
结束
类API