Whitelisting Nested Parameters in Rails -


i have params hash following structure (it built using fields_for)

=> {"utf8"=>"✓",     "daily_log"=>       {"id"=>"1",        "entries_attributes"=>           {"0"=>               {"count"=>"",                "hours"=>"",                "minutes"=>"",               }           }        },     "controller"=>"entries",     "action"=>"create"} 

i'm trying create entries_attributes_params method should return whitelisted version of params['daily_log']['entries_attributes']. unfortunately, keeps coming {} when call method.

the following works

def entries_attributes_params`    params[:daily_log][:entries_attributes].permit! end 

but want avoid using permit!. tried following:

def entries_attributes_params     params[:daily_log][:entries_attributes].permit(:count, :hours, :minutes) end 

this doesn't work. {} back.

i tried wrapping attributes pass permit [], doesn't work.

...permit([...attributes...]) 

how do this?

try this:

def entries_attributes_params   params_hash = params.require(:daily_log).permit(:id, entries_attributes: [:count, :hours, :minutes])   params_hash[:entries_attributes] end 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -