Skip to content
This repository was archived by the owner on Aug 17, 2017. It is now read-only.

Change readme code examples to be more explicit #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ With this plugin Action Controller parameters are forbidden to be used in Active

In addition, parameters can be marked as required and flow through a predefined raise/rescue flow to end up as a 400 Bad Request with no effort.


``` ruby
class PeopleController < ActionController::Base
# This will raise an ActiveModel::ForbiddenAttributes exception because it's using mass assignment
# without an explicit permit step.
def create
Person.create(params[:person])
end
end
```
This will raise an ActiveModel::ForbiddenAttributes exception because it's using mass assignment without an explicit permit step.

# This will pass with flying colors as long as there's a person key in the parameters, otherwise
# it'll raise a ActionController::MissingParameter exception, which will get caught by
# ActionController::Base and turned into that 400 Bad Request reply.
def update
person = current_account.people.find(params[:id])
person.update_attributes!(person_params)
redirect_to person

``` ruby
class PeopleController < ActionController::Base
def create
Person.create(person_params)
end

private
Expand All @@ -31,6 +31,7 @@ class PeopleController < ActionController::Base
end
end
```
This will pass with flying colors as long as there's a person key in the parameters, otherwise it'll raise a ActionController::MissingParameter exception, which will get caught by ActionController::Base and turned into that 400 Bad Request reply.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be ActionController::ParameterMissing instead.

I believe mine #158 can be closed when your pull request is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Language could, perhaps, be a little less flowery.


## Permitted Scalar Values

Expand Down