hashrocket / decent_exposure

A helper for creating declarative interfaces in controllers
MIT License
1.81k stars 107 forks source link

:build_params for #new action #162

Closed nashbridges closed 8 years ago

nashbridges commented 8 years ago

This is another regression (feature?) from v2.

Previously I can prefill edit form by passing params in an URL as such:

/invoices/new?invoice[amount]=300&invoice[currency]=USD

In v3 default :build_params are empty for GET request, so it no longer works.

Sure, I can fix it by providing build_params: ->{ invoice_params }, but I don't quite understand the reason for this logic.

mattpolito commented 8 years ago

Were you using a strong parameters strategy with the previous implementation?

nashbridges commented 8 years ago

No, the default one – ActiveRecordWithEagerAttributesStrategy, which handled new records correctly

mattpolito commented 8 years ago

Since decent_exposure is looking for a [exposure_name]_params method, which users tend to utilize with strong parameters, we've blocked GET requests from taking params. By utilizing the custom build_params method you've bypassed that check... making it work for you.

We looked into making this work the way you'd like but have decided it may cause more pain for most other users with [exposure_name]_params methods already defined. So I think that the build_params override would be the best way to handle your particular usage case.

nashbridges commented 8 years ago

OK, now I see. Looks this is another candidate for https://github.com/hashrocket/decent_exposure/wiki/Api-changes-in-version-3

mattpolito commented 8 years ago

Thanks for understanding and using decent_exposure!