Skip to content

Instantly share code, notes, and snippets.

@kf4x
Last active November 2, 2015 08:05
Show Gist options
  • Save kf4x/ef23e31276241dfdab47 to your computer and use it in GitHub Desktop.
Save kf4x/ef23e31276241dfdab47 to your computer and use it in GitHub Desktop.
def create
# when a create occurs somthing like this is sent to server with a POST request.....
{
"utf8"=>"✓",
"authenticity_token"=>"some/crazy/token",
"transaction"=>{"name"=>"chik-fil-a",
"category_id"=>"1",
"amount"=>"1.1"},
"commit"=>"Create Transaction"
}
# look at line 4 "transaction"=> that to access it you do
params[:transaction]
# params is the hashmap or dictionary variable name
# java you would params.get("transaction");
# so :transaction is the "key"
#
# so.. to get category_id
params[:transaction][:category_id]
# or java params.get("transaction").get("category_id");
# so now look...
params.require(:transaction).permit(:name, :category_id, :amount)
# it means given the params make sure(require) there is a key ":transaction"
# then is says given that dictionary or map only allow the keys listed. if only
# those are present then it passes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment