Skip to content

Instantly share code, notes, and snippets.

@webdev
Created April 29, 2010 22:47
Show Gist options
  • Save webdev/384397 to your computer and use it in GitHub Desktop.
Save webdev/384397 to your computer and use it in GitHub Desktop.
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment