Created
August 27, 2011 00:26
-
-
Save etdebruin/1174769 to your computer and use it in GitHub Desktop.
Campaign
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 Campaign < ActiveRecord::Base | |
belongs_to :user | |
#scope :active, where(:active => true) | |
#scope :not_yet_active, where(:active => false) | |
validates :goal, :presence => true | |
validates :url, :presence => true | |
validates :name_or_twitter, :presence => true | |
attr_accessor :complete_tweet | |
def full_tweet | |
unless self.campaign_url.nil? | |
self.complete_tweet = "#{self.tweet} #{self.campaign_url} #{MyGivingTweetConf::HASHTAG}" | |
else | |
self.complete_tweet = "#{self.tweet} http://bit.ly/XXXXX #{MyGivingTweetConf::HASHTAG}" | |
end | |
end | |
class CampaignsController < ApplicationController | |
# via Ajax start link on Campaign detail screen | |
def start | |
@campaign = Campaign.find(params[:id]) | |
@campaign.link = request.env['HTTP_HOST'] | |
status = @campaign.send_tweet(@campaign.complete_tweet) | |
logger.info(status) | |
if status.id | |
@campaign.set_first_tweet_id(status.id) | |
@campaign.activate | |
@campaign.cache_tweet(status) | |
@campaign.save | |
end | |
respond_to do |format| | |
format.json { render :json => @campaign } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment