Use strong parameters for Donation

This commit is contained in:
Matchu 2023-07-29 10:29:09 -07:00 committed by Matchu
parent f9cd563c82
commit 23b84cba26
2 changed files with 7 additions and 3 deletions

View file

@ -25,7 +25,7 @@ class DonationsController < ApplicationController
def update def update
@donation = Donation.from_param(params[:id]) @donation = Donation.from_param(params[:id])
@donation.update_attributes params[:donation] @donation.attributes = donation_params
feature_params = params[:feature] || {} feature_params = params[:feature] || {}
@features = @donation.features.find(feature_params.keys) @features = @donation.features.find(feature_params.keys)
@ -47,4 +47,10 @@ class DonationsController < ApplicationController
redirect_to @donation redirect_to @donation
end end
end end
private
def donation_params
params.require(:donation).permit(:donor_name)
end
end end

View file

@ -1,8 +1,6 @@
class Donation < ActiveRecord::Base class Donation < ActiveRecord::Base
FEATURE_COST = 500 # in cents = $5.00 FEATURE_COST = 500 # in cents = $5.00
attr_accessible :donor_name
belongs_to :campaign belongs_to :campaign
belongs_to :user belongs_to :user
has_many :features, class_name: 'DonationFeature' has_many :features, class_name: 'DonationFeature'