Guest User

Untitled

a guest
May 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ## Controller
  2. class Program < ActiveRecord::Base
  3. #enum_attr :status, %w(pending live on_hold completed)
  4. #enum_attr :kind, %w(social_video youtube facebook twitter)
  5.  
  6. has_one :flight, :dependent => :destroy
  7. has_one :creative, :dependent => :destroy
  8. accepts_nested_attributes_for :flight
  9. accepts_nested_attributes_for :creative
  10.  
  11. belongs_to :campaign
  12. belongs_to :advertiser
  13.  
  14. validates_presence_of :advertiser_id
  15. validates_presence_of :campaign_id
  16.  
  17. # attr_accessor :status
  18. # attr_accessor :kind
  19.  
  20. def initialize(*params)
  21. super(@params)
  22. @status = ['pending', 'live', 'on_hold', 'completed']
  23.  
  24. @kind = {
  25. :social_video => 'Social Video',
  26. :youtube => 'Youtube',
  27. :facebook => 'Facebook',
  28. :twitter => 'Twitter'
  29. }
  30. end
  31.  
  32. def new_flight_attributes=(flight_attributes)
  33. flight_attributes.each do |attribute|
  34. flight.build(attributes)
  35. end
  36. end
  37.  
  38. end
  39.  
  40. ## Model
  41. def create
  42. #@program = Program.new
  43. #@program.attributes = params[:program]
  44.  
  45. @program = Program.create(params[:program])
  46.  
  47. @campaign = @program.campaign
  48. @program.save ? redirect_to(edit_campaign_program_path(@campaign, @program)) : render(:action => :new)
  49. end
Add Comment
Please, Sign In to add comment