Rails 4: get list of permitted attributes (strong parameters) from a controller

末鹿安然 提交于 2019-12-11 03:58:00

问题


I'm trying to automate some documentation for an API and would like to retrieve the list of attributes listed by strong_parameters, as that's really the public face of my API.

What I would like to do:

def MyController < ApplicationController
  # ...CRUD actions...

  private
  def my_params
    require(:resource).permit(:first_name, :last_name, :age)
  end
end

MyController.my_params => [:first_name, :last_name, :age]

Typically the listing is marked as private, so that's the first issue. I don't want to maintain 2 separate lists of attributes for a resource, so I would really like to access the actual values permitted by the code to keep my automated documentation accurate.

So far it looks like the params listing is not accessible outside the controller.

来源:https://stackoverflow.com/questions/31686791/rails-4-get-list-of-permitted-attributes-strong-parameters-from-a-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!