feat(campaign_gift_option): add strong params

This commit is contained in:
Luis Castro 2019-08-06 14:36:31 +02:00 committed by Eric Schultz
parent 399c421f38
commit 51a4902991
2 changed files with 18 additions and 14 deletions

View file

@ -17,14 +17,14 @@ class CampaignGiftOptionsController < ApplicationController
def create def create
campaign = current_campaign campaign = current_campaign
json_saved CreateCampaignGiftOption.create(campaign, params[:campaign_gift_option]), json_saved CreateCampaignGiftOption.create(campaign, campaign_gift_option_params),
'Gift option successfully created!' 'Gift option successfully created!'
end end
def update def update
@campaign = current_campaign @campaign = current_campaign
gift_option = @campaign.campaign_gift_options.find params[:id] gift_option = @campaign.campaign_gift_options.find params[:id]
json_saved UpdateCampaignGiftOption.update(gift_option, params[:campaign_gift_option]), 'Successfully updated' json_saved UpdateCampaignGiftOption.update(gift_option, campaign_gift_option_params), 'Successfully updated'
end end
# put /nonprofits/:nonprofit_id/campaigns/:campaign_id/campaign_gift_options/update_order # put /nonprofits/:nonprofit_id/campaigns/:campaign_id/campaign_gift_options/update_order
@ -39,4 +39,10 @@ class CampaignGiftOptionsController < ApplicationController
render_json { DeleteCampaignGiftOption.delete(@campaign, params[:id]) } render_json { DeleteCampaignGiftOption.delete(@campaign, params[:id]) }
end end
private
def campaign_gift_option_params
params.require(:campaign_gift_option).permit(:amount_one_time, :amount_recurring, :amount_dollars, :description, :name, :campaign, :quantity, :to_ship, :order, :hide_contributions)
end
end end

View file

@ -2,18 +2,16 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
class CampaignGiftOption < ApplicationRecord class CampaignGiftOption < ApplicationRecord
# TODO # :amount_one_time, #int (cents)
# attr_accessible \ # :amount_recurring, #int (cents)
# :amount_one_time, #int (cents) # :amount_dollars, #str, gets converted to amount
# :amount_recurring, #int (cents) # :description, # text
# :amount_dollars, #str, gets converted to amount # :name, # str
# :description, # text # :campaign, #assocation
# :name, # str # :quantity, #int (optional)
# :campaign, #assocation # :to_ship, #boolean
# :quantity, #int (optional) # :order, #int (optional)
# :to_ship, #boolean # :hide_contributions #boolean (optional)
# :order, #int (optional)
# :hide_contributions #boolean (optional)
belongs_to :campaign belongs_to :campaign
has_many :campaign_gifts has_many :campaign_gifts