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(' ')}"
|
||||
end
|
||||
|
||||
def to_tweet(url)
|
||||
tweet = to_s
|
||||
if (tweet.size + url.size >= 140)
|
||||
tweet = tweet[0, tweet[0, 140 - url.size].rindex(/\s/)]
|
||||
def to_tweet
|
||||
url = Rails.application.routes.url_helpers.event_url(
|
||||
self,
|
||||
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
|
||||
"#{tweet} #{url}"
|
||||
tweet
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -33,6 +33,6 @@ class EventCallbacks
|
||||
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
|
||||
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
|
||||
end
|
||||
client.update "#{event.to_tweet event_url(event)}" if client.consumer_key
|
||||
client.update event.to_tweet if client.consumer_key
|
||||
end
|
||||
end
|
||||
|
@ -1,18 +1,18 @@
|
||||
%h2
|
||||
%em.fa.fa-exclamation-triangle
|
||||
=t '.title'
|
||||
= t '.title'
|
||||
|
||||
- if @event.locality?
|
||||
%h2.warning=t '.warning'
|
||||
%h2.warning= t '.warning'
|
||||
|
||||
= form_for @moderation, url: { action: :accept }, html: { method: :put } do |f|
|
||||
= link_to moderations_path do
|
||||
%em.fa.fa-arrow-left
|
||||
=t '.ko'
|
||||
= t '.ko'
|
||||
|
||||
= f.button do
|
||||
%em.fa.fa-thumbs-up
|
||||
=t '.ok'
|
||||
= t '.ok'
|
||||
|
||||
- if ENV['TWITTER_CONSUMER_KEY'] || Rails.env.development?
|
||||
%fieldset
|
||||
@ -20,12 +20,12 @@
|
||||
%em.fa.fa-twitter
|
||||
Tweet
|
||||
|
||||
%h3=t '.tweet_helper'
|
||||
%h3= t '.tweet_helper'
|
||||
|
||||
= @event.to_tweet event_url @event
|
||||
= @event.to_tweet
|
||||
|
||||
%fieldset
|
||||
%legend
|
||||
%em.fa.fa-calendar
|
||||
=Event.model_name.human
|
||||
= Event.model_name.human
|
||||
= render file: '/events/show'
|
||||
|
Loading…
Reference in New Issue
Block a user