Meilleure gestion de la limite des 140 caractères dans twitter

This commit is contained in:
echarp 2014-10-04 19:13:19 +02:00
parent f5ded6c84e
commit 50c021368d
3 changed files with 10 additions and 3 deletions

View File

@ -101,7 +101,7 @@ class ModerationsController < ApplicationController
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
end
client.update "#{@event} #{events_url @event}" if client.consumer_key
client.update "#{@event.to_tweet url}" if client.consumer_key
end
def send_destroy_mails

View File

@ -99,6 +99,14 @@ class Event < ActiveRecord::Base
"#{start_time.to_date} #{city}: #{title} #{hashtags.join(' ')}"
end
def to_tweet(url)
tweet = to_s
if (tweet.size + url.size >= 140)
tweet = tweet[0, tweet[0, 140 - url.size].rindex(/\s/)]
end
"#{tweet} #{url}"
end
private
def end_after_start

View File

@ -22,8 +22,7 @@
%h3=t '.tweet_helper'
= @event
= events_url @event
= @event.to_tweet events_url @event
%fieldset
%legend