Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permitting array of arrays with strong parameters in rails

I have searched everywhere but does anyone know if it is possible to permit and array of arrays using strong parameters in rails? My code looks like this:

params.require(:resource).permit(:foo, :bar => [[:baz, :bend]])

This is giving me:

ArgumentError (wrong number of arguments (0 for 1..2))

I have also tried:

params.require(:resource).permit(:foo, :bar => [[]])
params.require(:resource).permit(:foo, :bar => [][])
params.require(:resource).permit(:foo, :bar => [])

But these all give me invalid parameter errors or do not process the parameters.

Thanks in advance for any help

like image 900
James Sanders Avatar asked Jun 22 '15 15:06

James Sanders


1 Answers

Looking at the code I think this is not possible. you have to flatten the second level.

 def permit(*filters)
  params = self.class.new

  filters.each do |filter|
    case filter
    when Symbol, String
      permitted_scalar_filter(params, filter)
    when Hash then
      hash_filter(params, filter)
    end
  end

  unpermitted_parameters!(params) if self.class.action_on_unpermitted_parameters

  params.permit!
end
like image 190
pg77 Avatar answered Sep 27 '22 18:09

pg77