Correction so that the tweet url is actually well generated
This commit is contained in:
parent
31d64d636a
commit
791b9d58b0
@ -103,12 +103,16 @@ class Event < ActiveRecord::Base
|
|||||||
"#{start_time.to_date} #{city}: #{title} #{hashtags.join(' ')}"
|
"#{start_time.to_date} #{city}: #{title} #{hashtags.join(' ')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_tweet(url)
|
def to_tweet
|
||||||
tweet = to_s
|
url = Rails.application.routes.url_helpers.event_url(
|
||||||
if (tweet.size + url.size >= 140)
|
self,
|
||||||
tweet = tweet[0, tweet[0, 140 - url.size].rindex(/\s/)]
|
host: ActionMailer::Base.default_url_options[:host])
|
||||||
|
|
||||||
|
tweet = "#{self} #{url}"
|
||||||
|
if (tweet.size >= 140)
|
||||||
|
tweet = "#{tweet[0, tweet.rindex(/\s/, 140 - url.size)]} #{url}"
|
||||||
end
|
end
|
||||||
"#{tweet} #{url}"
|
tweet
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -33,6 +33,6 @@ class EventCallbacks
|
|||||||
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
|
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
|
||||||
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
|
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
|
||||||
end
|
end
|
||||||
client.update "#{event.to_tweet event_url(event)}" if client.consumer_key
|
client.update event.to_tweet if client.consumer_key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
%h3= t '.tweet_helper'
|
%h3= t '.tweet_helper'
|
||||||
|
|
||||||
= @event.to_tweet event_url @event
|
= @event.to_tweet
|
||||||
|
|
||||||
%fieldset
|
%fieldset
|
||||||
%legend
|
%legend
|
||||||
|
Loading…
Reference in New Issue
Block a user