tksask
tksask

Reputation: 105

Rails 5 - strong parameters: array of hashes

I'm sending these Parameters on my request:

{"rss":[{"rss":"http://sneakernews.com/feed/","type":"2"},{"type":"4","rss":"https://forum.unity3d.com/forums/-/index.rss"}]}

On my controller I'm doing this:

rss = rss_params[:rss]

def rss_params
    params.permit(:rss => [:type, :rss])
end

But I'm always getting this:

["#<ActionController::Parameters:0x007faf809281a0>", "#<ActionController::Parameters:0x007faf700b75a8>"]

How can I retrieve the hashes?

Upvotes: 4

Views: 2567

Answers (1)

nmott
nmott

Reputation: 9604

In Rails 5 just iterate over them and then permit each hash

params.require(:rss).map do |p|
  p.permit(:rss, :type)
end

Upvotes: 4

Related Questions