Created
March 28, 2015 13:18
-
-
Save breim/96115ab9594e18ea3cd5 to your computer and use it in GitHub Desktop.
model test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Company < ActiveRecord::Base | |
# Relations | |
belongs_to :user | |
belongs_to :type | |
has_many :posts | |
has_many :members | |
accepts_nested_attributes_for :members, :reject_if => :all_blank, :allow_destroy => true | |
# Validations | |
validates :name, presence: true, if: :step1? | |
validates :slogan, presence: true, if: :step1? | |
validates :site_url, :format => URI::regexp(%w(http https)), :allow_blank => true, if: :step1? | |
validates :facebook_url, :format => URI::regexp(%w(http https facebook)), :allow_blank => true, if: :step2? | |
validates :twitter_url, :format => URI::regexp(%w(http https twitter)), :allow_blank => true, if: :step2? | |
validates :linkedin_url, :format => URI::regexp(%w(http https linkedin)), :allow_blank => true, if: :step2? | |
validates :video_pitch, :format => URI::regexp(%w(http https youtube)), :allow_blank => true, if: :step4? | |
validates :foundation_date, presence: true, if: :step2? | |
validates :team_qtd,presence: true, if: :step2? | |
validates :type_id, presence: true, if: :step2? | |
validates :location, presence: true, if: :step2? | |
validates :stage, presence: true, if: :step2? | |
validates :description, presence: true, if: :step1? | |
# Can be likeable ? (Socialization gem) | |
acts_as_likeable | |
# Multi-Step Form | |
include MultiStepModel | |
def self.total_steps | |
5 | |
end | |
# PaperClip + ftp | |
has_attached_file :image,:styles => { | |
:large => "512x512" , | |
:medium => "200x200" , | |
:small => "168x168", | |
:thumb => "40x40", | |
:tiny => "32x32" | |
}, | |
:default_url => :set_default_url | |
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ | |
validates_attachment_size :image, :less_than => 10.megabytes | |
# if user dont have image | |
def set_default_url | |
"/img/missing.png" | |
end | |
# End --- | |
# After and before validations | |
include Searchable | |
# FriendlyID Gem | |
extend FriendlyId | |
friendly_id :slug_candidates, use: :slugged | |
def slug_candidates | |
[:name, | |
[:name, :id] | |
] | |
end | |
# end | |
# Geocoder GEM | |
geocoded_by :location do |obj, results| | |
if geo = results.first | |
# populate your model | |
obj.latitude = geo.latitude | |
obj.longitude = geo.longitude | |
obj.city = geo.city | |
obj.state = geo.state | |
else | |
obj.location = nil | |
end | |
end | |
before_validation :geocode, :if => :location_changed? | |
# Geocoder end | |
# Send subscribe email ( Mail Chimp ) | |
after_create :send_subscribe | |
def send_subscribe | |
mail_chimp_api = ENV['MAIL_CHIMP_API'] | |
mailchimp = Mailchimp::API.new(mail_chimp_api) | |
mail_chimp_list_user = ENV['MAIL_CHIMP_LIST_COMPANY'] | |
mailchimp.lists.subscribe(mail_chimp_list_user, :email => self.user.email, :merge_vars => { :FNAME => self.user.name, :LNAME => "", },:mc_language => "pt" ,:email_type => 'html', :double_optin => false, :update_existing => true, :replace_interests => true, :send_welcome => false) | |
rescue Exception => e | |
puts e | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment