houdini/app/models/campaign_template.rb

51 lines
1.1 KiB
Ruby
Raw Normal View History

class CampaignTemplate < ActiveRecord::Base
2018-05-18 15:18:46 +00:00
CUSTOMIZABLE_ATTR = %i(goal_amount)
attr_accessible \
:template_name,
:name, # refers to campaign name
:tagline,
:goal_amount,
2018-05-18 15:18:46 +00:00
:goal_amount_dollars, # accessor: translated into goal_amount (cents)
:main_image,
:remove_main_image, # for carrierwave
:video_url,
:vimeo_video_id,
:youtube_video_id,
:summary,
2018-05-18 15:18:46 +00:00
:body,
:end_datetime,
:goal_customizable,
:nonprofit_id
2018-05-18 15:18:46 +00:00
attr_accessor :end_datetime
attr_accessor :goal_amount_dollars
has_many :campaigns
2018-05-18 15:18:46 +00:00
belongs_to :nonprofit
mount_uploader :main_image, CampaignTemplateMainImageUploader
2018-05-18 15:18:46 +00:00
before_validation do
if self.goal_amount_dollars.present?
self.goal_amount = (self.goal_amount_dollars.gsub(',','').to_f * 100).to_i
end
self
end
def customizable_attribute?(attribute_name)
CUSTOMIZABLE_ATTR.include? attribute_name.to_sym
2018-05-18 15:18:46 +00:00
end
def customizable_attributes_list
CUSTOMIZABLE_ATTR
2018-05-18 15:18:46 +00:00
end
2018-05-21 19:24:13 +00:00
def create_campaign_params
excluded = %w(
id template_name created_at updated_at
)
attributes.except!(*excluded)
end
end