Skip to content

Instantly share code, notes, and snippets.

@omarqureshi
Forked from webdev/gist:384397
Created April 29, 2010 22:52
Show Gist options
  • Save omarqureshi/384400 to your computer and use it in GitHub Desktop.
Save omarqureshi/384400 to your computer and use it in GitHub Desktop.
## Controller
class Program < ActiveRecord::Base
STATUSES = %w(pending live on_hold completed)
KINDS = %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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment