Reddirt
Reddirt

Reputation: 5953

Rails4 PG hstore Unpermitted parameters: data

I have a Rails4 app using PG hstore.

This is from the console:

enter image description here

This is the Vehicle Controller:

    def vehicle_params
      params.require(:vehicle).permit(:description, :stufftype_id, :name, :tenant_id, :count, :manufacturer, :man_date, :purchase_date, :purchase_price, :current_price, :warranty_date, :model, :notes, :site_id, :sell, :loaned, :borrowed, :sell_to, :borrowed_from, :sale_id, :sale_price, :sold_amount, :sold, :archive, :vendor_id, :loaned_to, :data)
    end

It contains :data

So, why is data an unpermitted parameter?

Thanks for the help!

Upvotes: 1

Views: 923

Answers (1)

Marc Lainez
Marc Lainez

Reputation: 3080

When you permit :data in your strong parameters, it only permits scalar value.

Scalar values can be of type String, Symbol, NilClass, Numeric, TrueClass, FalseClass, Date, Time, DateTime, StringIO, IO, ActionDispatch::Http::UploadedFile and Rack::Test::UploadedFile as described in the strong parameters documentation:

https://github.com/rails/strong_parameters#permitted-scalar-values

It means that passing a Hash for :data in the params hash, will not be permitted as is.

What you are looking for is a way to permit nested parameters. Also described in the documentation:

https://github.com/rails/strong_parameters#nested-parameters

And if your hstore keys are dynamic, you can whitelist the dynamic hash yourself using the method described in the following SO question:

rails 4 strong params + dynamic hstore keys

Hope that helps.

Upvotes: 2

Related Questions