rails 4 strong params + dynamic hstore keys

前端 未结 3 1850
长发绾君心
长发绾君心 2020-12-14 21:15

I\'m having a problem overcoming the new strong params requirement in Rails 4 using Hstore and dynamic accessors

I have an Hstore column called :content

3条回答
  •  心在旅途
    2020-12-14 22:15

    If I understand correctly, you would like to whitelist a hash of dynamic keys. You can use some ruby code as follows to do this:

    params.require(:article).permit(:name).tap do |whitelisted|
      whitelisted[:content] = params[:article][:content] 
    end
    

    This worked for me, hope it helps!

提交回复
热议问题