Created
May 2, 2014 15:14
-
-
Save pier-oliviert/6683cf8477c7fbb863b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyController < ApplicationController | |
| def create | |
| params_array_not_supported.each do |offer| # KABOOOM! | |
| ... | |
| end | |
| offers_params_not_chanaible_with_array.each do |offer_param| | |
| Offer.new offer_param # ActiveModel::ForbiddenAttributes | |
| end | |
| offers_params.each do |offer_param| | |
| Offer.new offer_param # OK | |
| end | |
| end | |
| protected | |
| def params_array_not_supported | |
| params.require(:offers).permit(:amount) #Array does not respond to permit() | |
| end | |
| def offers_params_not_chanaible_with_array | |
| params.require(:offers).each do |offer| | |
| offer.permit(:amount) | |
| end | |
| def offers_params | |
| params.require(:offers).map do |offer| | |
| offer.permit(:amount) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "offers"=>[{"amount"=>"5"}, {"amount"=>"5"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment