Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Controller
- class Program < ActiveRecord::Base
- #enum_attr :status, %w(pending live on_hold completed)
- #enum_attr :kind, %w(social_video youtube facebook twitter)
- has_one :flight, :dependent => :destroy
- has_one :creative, :dependent => :destroy
- accepts_nested_attributes_for :flight
- accepts_nested_attributes_for :creative
- belongs_to :campaign
- belongs_to :advertiser
- validates_presence_of :advertiser_id
- validates_presence_of :campaign_id
- # attr_accessor :status
- # attr_accessor :kind
- def initialize(*params)
- super(@params)
- @status = ['pending', 'live', 'on_hold', 'completed']
- @kind = {
- :social_video => 'Social Video',
- :youtube => 'Youtube',
- :facebook => 'Facebook',
- :twitter => 'Twitter'
- }
- end
- def new_flight_attributes=(flight_attributes)
- flight_attributes.each do |attribute|
- flight.build(attributes)
- end
- end
- end
- ## Model
- def create
- #@program = Program.new
- #@program.attributes = params[:program]
- @program = Program.create(params[:program])
- @campaign = @program.campaign
- @program.save ? redirect_to(edit_campaign_program_path(@campaign, @program)) : render(:action => :new)
- end
Add Comment
Please, Sign In to add comment