ruby rails request model idea


SUBMITTED BY: Guest

DATE: Sept. 29, 2014, 5:56 p.m.

FORMAT: Text only

SIZE: 1.8 kB

HITS: 1429

  1. require 'delayed_job'
  2. class Request < ActiveRecord::Base
  3. attr_accessible :title, :description, :meta, :videos_attributes, :credentials_attributes, :timestamp_form
  4. belongs_to :user
  5. has_many :credentials, :dependent => :delete_all
  6. has_many :link_urls, :dependent => :delete_all
  7. has_many :videos, :dependent => :delete_all
  8. validates_associated :credentials, :length => {:minimum => 1}
  9. accepts_nested_attributes_for :credentials, :allow_destroy => true
  10. accepts_nested_attributes_for :link_urls, :allow_destroy => true
  11. accepts_nested_attributes_for :videos
  12. validates_presence_of :title, :description, :meta, :timestamp_form, :videos
  13. validates_length_of :meta, :minimum => 3, :maximum => 30, :tokenizer => lambda{ |value| value.split(',') }, :too_short => "must have at least %{count} keywords", :too_long => "must have at most %{count} keywords"
  14. validates_uniqueness_of :timestamp_form
  15. def with_credentials_for(usr)
  16. SiteTemplate.active.compatible_with(usr).each do |st|
  17. credentials.build :name => st.name, :sitetemplate_id => st.id, :flag_sub => st.flag_sub, :flag => st.flag, :flag_cat => st.flag_cat
  18. end
  19. self
  20. end
  21. def with_linkurls_for(usr)
  22. SiteTemplate.active.compatible_with(usr).each do |st|
  23. link_urls.build :sitetemplate_id => st.id, :name => st.name
  24. end
  25. self
  26. end
  27. def with_video_for(usr)
  28. videos.build :user_id => @user
  29. self
  30. end
  31. def upload(request)
  32. video = Video.find_by_request_id(request.id)
  33. request.credentials.checked.each do |link|
  34. puts link.pwd
  35. puts link.encrypted_pwd
  36. link.delay.distribute(link,request,video)
  37. end
  38. end
  39. end

comments powered by Disqus