String keys make directory structure
Add this line to your application's Gemfile:
gem 'folder'
And then execute:
$ bundle
Or install it yourself as:
$ gem install folder
Like this
h = {'a.b.c' => 'd'}
p h.fold #=> {"a"=>{"b"=>{"c"=>"d"}}}
p h #=> {"a.b.c"=>"d"}
p h.fold! #=> {"a"=>{"b"=>{"c"=>"d"}}}
p h #=> {"a"=>{"b"=>{"c"=>"d"}}}
h = {'a/b/c' => 'd'}
p h.fold #=> {"a/b/c"=>"d"}
p h.fold('/') #=> {"a"=>{"b"=>{"c"=>"d"}}}
Controller
class ExampleController < ApplicationController
def create
render json: Example.create!(example_params)
end
protected
def example_params
params.fold.require(:example)
.permit(:nyan, :mew)
end
end
Request
curl http://localhost:3000/example.json -d example.nyan=neko -d example.mew=koneko
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request