README.md in attribeauty-0.3.1 vs README.md in attribeauty-0.3.2

- old
+ new

@@ -82,10 +82,12 @@ ## Params Experimental params sanitizer is now available. This will cast your params, and remove elements you want to exclude if `nil` or `empty` +Why is this needed? Params arrive into the controller in a messy state. Booleans are not ready for caparison, integers are often strings, empty strings, and nils abound. Rails does the casting of params at the model, which is simple and elegant, but in many cases, these params are used for a multitude of things before hitting the database. I truly believe we need to cast them before they do anything. + ``` # app/controllers/my_controller.rb class MyController def update MyRecord.update(update_params) @@ -147,10 +149,49 @@ end end ``` -See `test/test_params.rb` for what is expected. +If you want to raise an error, rather than just return the errors in an array, use the `accept!` method. Will raise `Attribeauty::MissingAttributeError` with the required elements: + + +``` +class MyController + def update + MyRecord.update(update_params) + + redirect_to index_path + end + + private + + # your params look like this: + # { user: { profile: [{ address: { street_name: "Main St" } }] } } + # + def params_filter + Attribeauty::Params.with(request.params) + end + + # This following with the accept! method + # will raise: Attribeauty::MissingAttributeError, "title required, email required" + # + def update_params + params_filter.accept! do + container :user do + attribute :title, :string, allow_nil: false, required: true + attribute :email do + attribute :address, :string, allow_empty: false + attribute :valid, :boolean, allow_nil: false + attribute :ip_address, :string, allow_blank: true + end + end + end + end +end + +``` + +See `test/test_params.rb` for more examples ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.